$HandInvThrowTimeout = 0.8 * 1000; // 1/2 second between throwing grenades or mines

$WeaponsHudData[0, bitmapName]   = "gui/hud_targetlaser";
$WeaponsHudData[0, itemDataName] = "TargetingLaser";
$WeaponsHudData[0, reticle] = "gui/hud_ret_targlaser";
$WeaponsHudData[0, visible] = "false";

$WeaponsHudData[1, bitmapName]   = "gui/hud_shocklance";
$WeaponsHudData[1, itemDataName] = "ShockLance";
$WeaponsHudData[1, reticle] = "gui/hud_ret_shocklance";
$WeaponsHudData[1, visible] = "false";

$WeaponsHudData[2, bitmapName]   = "gui/hud_shocklance";
$WeaponsHudData[2, itemDataName] = "ConstructionTool";
$WeaponsHudData[2, reticle] = "gui/hud_ret_sniper";
$WeaponsHudData[2, visible] = "false";

$WeaponsHudData[3, bitmapName] = "gui/hud_chaingun";
$WeaponsHudData[3, itemDataName] = "SuperChaingun";
$WeaponsHudData[3, reticle] = "gui/ret_chaingun";
$WeaponsHudData[3, visible] = "true";

$WeaponsHudData[4, bitmapName]   = "gui/hud_grenlaunch";
$WeaponsHudData[4, itemDataName] = "MergeTool";
$WeaponsHudData[4, reticle] = "gui/ret_mortor";
$WeaponsHudData[4, visible] = "true";

$WeaponsHudData[5, bitmapName]   = "gui/hud_chaingun";
$WeaponsHudData[5, itemDataName] = "pistol";
$WeaponsHudData[5, ammoDataName] = "pistolAmmo";
$WeaponsHudData[5, reticle] = "gui/ret_chaingun";
$WeaponsHudData[5, visible] = "true";

$WeaponsHudData[6, bitmapName]   = "gui/hud_shocklance";
$WeaponsHudData[6, itemDataName] = "melee";
$WeaponsHudData[6, reticle] = "gui/hud_ret_shocklance";
$WeaponsHudData[6, visible] = "false";

$WeaponsHudData[7, bitmapName]   = "gui/hud_sniper";
$WeaponsHudData[7, itemDataName] = "S3Rifle";
$WeaponsHudData[7, ammoDataName] = "S3RifleAmmo";
$WeaponsHudData[7, reticle] = "gui/ret_chaingun";
$WeaponsHudData[7, visible] = "true";

$WeaponsHudData[8, bitmapName]   = "gui/hud_plasma";
$WeaponsHudData[8, itemDataName] = "M1700";
$WeaponsHudData[8, ammoDataName] = "M1700Ammo";
$WeaponsHudData[8, reticle] = "gui/ret_plasma";
$WeaponsHudData[8, visible] = "true";

$WeaponsHudData[9, bitmapName]   = "gui/hud_sniper";
$WeaponsHudData[9, itemDataName] = "G41Rifle";
$WeaponsHudData[9, ammoDataName] = "G41RifleAmmo";
$WeaponsHudData[9, reticle] = "gui/ret_chaingun";
$WeaponsHudData[9, visible] = "true";

$WeaponsHudData[10, bitmapName]   = "gui/hud_sniper";
$WeaponsHudData[10, itemDataName] = "R700SniperRifle";
$WeaponsHudData[10, ammoDataName] = "R700SniperRifleAmmo";
$WeaponsHudData[10, reticle] = "gui/ret_chaingun";
$WeaponsHudData[10, visible] = "true";

$WeaponsHudData[11, bitmapName]   = "gui/hud_chaingun";
$WeaponsHudData[11, itemDataName] = "MP26";
$WeaponsHudData[11, ammoDataName] = "MP26Ammo";
$WeaponsHudData[11, reticle] = "gui/ret_chaingun";
$WeaponsHudData[11, visible] = "true";

$WeaponsHudData[12, bitmapName]   = "gui/hud_chaingun";
$WeaponsHudData[12, itemDataName] = "Pg700";
$WeaponsHudData[12, ammoDataName] = "Pg700Ammo";
$WeaponsHudData[12, reticle] = "gui/ret_chaingun";
$WeaponsHudData[12, visible] = "true";

$WeaponsHudData[13, bitmapName]   = "gui/hud_targetlaser";
$WeaponsHudData[13, itemDataName] = "UAVCaller";
$WeaponsHudData[13, reticle] = "gui/hud_ret_targlaser";
$WeaponsHudData[13, visible] = "true";

$WeaponsHudData[14, bitmapName]   = "gui/hud_sniper";
$WeaponsHudData[14, itemDataName] = "M1SniperRifle";
$WeaponsHudData[14, ammoDataName] = "M1SniperRifleAmmo";
$WeaponsHudData[14, reticle] = "gui/ret_chaingun";
$WeaponsHudData[14, visible] = "true";

$WeaponsHudData[15, bitmapName]   = "gui/hud_targetlaser";
$WeaponsHudData[15, itemDataName] = "AirstrikeCaller";
$WeaponsHudData[15, reticle] = "gui/hud_ret_targlaser";
$WeaponsHudData[15, visible] = "true";

$WeaponsHudData[16, bitmapName]   = "gui/hud_targetlaser";
$WeaponsHudData[16, itemDataName] = "HeliCaller";
$WeaponsHudData[16, reticle] = "gui/hud_ret_targlaser";
$WeaponsHudData[16, visible] = "true";

$WeaponsHudData[17, bitmapName]   = "gui/hud_missile";
$WeaponsHudData[17, itemDataName] = "MissileLauncher";
$WeaponsHudData[17, ammoDataName] = "MissileLauncherAmmo";
$WeaponsHudData[17, reticle] = "gui/ret_missile";
$WeaponsHudData[17, visible] = "true";

$WeaponsHudData[18, bitmapName]   = "gui/hud_chaingun";
$WeaponsHudData[18, itemDataName] = "RP432";
$WeaponsHudData[18, ammoDataName] = "RP432Ammo";
$WeaponsHudData[18, reticle] = "gui/ret_chaingun";
$WeaponsHudData[18, visible] = "true";

$WeaponsHudData[19, bitmapName]   = "gui/hud_chaingun";
$WeaponsHudData[19, itemDataName] = "MiniChaingun";
$WeaponsHudData[19, ammoDataName] = "MiniChaingunAmmo";
$WeaponsHudData[19, reticle] = "gui/ret_chaingun";
$WeaponsHudData[19, visible] = "true";

$WeaponsHudData[20, bitmapName]   = "gui/hud_plasma";
$WeaponsHudData[20, itemDataName] = "Wp400";
$WeaponsHudData[20, ammoDataName] = "Wp400Ammo";
$WeaponsHudData[20, reticle] = "gui/ret_plasma";
$WeaponsHudData[20, visible] = "true";

$WeaponsHudData[21, bitmapName]   = "gui/hud_plasma";
$WeaponsHudData[21, itemDataName] = "lasergun";
$WeaponsHudData[21, ammoDataName] = "lasergunAmmo";
$WeaponsHudData[21, reticle] = "gui/ret_plasma";
$WeaponsHudData[21, visible] = "true";

$WeaponsHudData[22, bitmapName]   = "gui/hud_missile";
$WeaponsHudData[22, itemDataName] = "RPG";
$WeaponsHudData[22, ammoDataName] = "RPGAmmo";
$WeaponsHudData[22, reticle] = "gui/ret_missile";
$WeaponsHudData[22, visible] = "true";

$WeaponsHudData[23, bitmapName]   = "gui/hud_shocklance";
$WeaponsHudData[23, itemDataName] = "BOV";
$WeaponsHudData[23, reticle] = "gui/hud_ret_shocklance";
$WeaponsHudData[23, visible] = "false";

$WeaponsHudData[24, bitmapName]   = "gui/hud_shocklance";
$WeaponsHudData[24, itemDataName] = "EditTool";
$WeaponsHudData[24, reticle] = "gui/hud_ret_sniper";
$WeaponsHudData[24, visible] = "false";

$WeaponsHudData[25, bitmapName]   = "gui/hud_shocklance";
$WeaponsHudData[25, itemDataName] = "EditorGun";
$WeaponsHudData[25, reticle] = "gui/hud_ret_sniper";
$WeaponsHudData[25, visible] = "false";

$WeaponsHudData[26, bitmapName]   = "gui/hud_plasma";
$WeaponsHudData[26, itemDataName] = "PulsePhaser";
$WeaponsHudData[26, reticle] = "gui/hud_ret_plasma";
$WeaponsHudData[26, visible] = "false";

$WeaponsHudData[27, bitmapName]   = "gui/hud_chaingun";
$WeaponsHudData[27, itemDataName] = "LD06Savager";
$WeaponsHudData[27, reticle] = "gui/hud_ret_plasma";
$WeaponsHudData[27, visible] = "false";

$WeaponsHudData[28, bitmapName]   = "gui/hud_missile";
$WeaponsHudData[28, itemDataName] = "IonLauncher";
$WeaponsHudData[28, ammoDataName] = "IonLauncherAmmo";
$WeaponsHudData[28, reticle] = "gui/ret_missile";
$WeaponsHudData[28, visible] = "true";

$WeaponsHudData[29, bitmapName]   = "gui/hud_sniper";
$WeaponsHudData[29, itemDataName] = "IonRifle";
$WeaponsHudData[29, reticle] = "gui/hud_ret_sniper";
$WeaponsHudData[29, visible] = "true";

$WeaponsHudData[30, bitmapName]   = "gui/hud_chaingun";
$WeaponsHudData[30, itemDataName] = "MG42";
$WeaponsHudData[30, ammoDataName] = "MG42Ammo";
$WeaponsHudData[30, reticle] = "gui/ret_chaingun";
$WeaponsHudData[30, visible] = "true";

$WeaponsHudData[31, bitmapName]   = "gui/hud_plasma";
$WeaponsHudData[31, itemDataName] = "flamer";
$WeaponsHudData[31, ammoDataName] = "flamerAmmo";
$WeaponsHudData[31, reticle] = "gui/hud_ret_plasma";
$WeaponsHudData[31, visible] = "true";

$WeaponsHudData[32, bitmapName]   = "gui/hud_sniper";
$WeaponsHudData[32, itemDataName] = "G17SniperRifle";
$WeaponsHudData[32, ammoDataName] = "G17SniperRifleAmmo";
$WeaponsHudData[32, reticle] = "gui/ret_chaingun";
$WeaponsHudData[32, visible] = "true";

$WeaponsHudData[33, bitmapName]   = "gui/hud_mortar";
$WeaponsHudData[33, itemDataName] = "ConcussionGun";
$WeaponsHudData[33, ammoDataName] = "ConcussionGunAmmo";
$WeaponsHudData[33, reticle] = "gui/ret_mortar";
$WeaponsHudData[33, visible] = "true";

$WeaponsHudData[34, bitmapName]   = "gui/hud_mortar";
$WeaponsHudData[34, itemDataName] = "ShadowRifle";
$WeaponsHudData[34, reticle] = "gui/ret_mortar";
$WeaponsHudData[34, visible] = "true";

$WeaponsHudData[35, bitmapName]   = "gui/hud_targetlaser";
$WeaponsHudData[35, itemDataName] = "GrappleHook";
$WeaponsHudData[35, reticle] = "gui/hud_ret_targlaser";
$WeaponsHudData[35, visible] = "true";

$WeaponsHudData[36, bitmapName]   = "gui/hud_mortar";
$WeaponsHudData[36, itemDataName] = "MiniColliderCannon";
$WeaponsHudData[36, reticle] = "gui/ret_mortar";
$WeaponsHudData[36, visible] = "true";

$WeaponsHudData[37, bitmapName]   = "gui/hud_sniper";
$WeaponsHudData[37, itemDataName] = "S3SRifle";
$WeaponsHudData[37, ammoDataName] = "S3SRifleAmmo";
$WeaponsHudData[37, reticle] = "gui/ret_chaingun";
$WeaponsHudData[37, visible] = "true";

$WeaponsHudData[38, bitmapName]   = "gui/hud_chaingun";
$WeaponsHudData[38, itemDataName] = "MP26CMDO";
$WeaponsHudData[38, ammoDataName] = "MP26CMDOAmmo";
$WeaponsHudData[38, reticle] = "gui/ret_Chaingun";
$WeaponsHudData[38, visible] = "true";

$WeaponsHudData[39, bitmapName]   = "gui/hud_plasma";
$WeaponsHudData[39, itemDataName] = "SA2400";
$WeaponsHudData[39, ammoDataName] = "SA2400Ammo";
$WeaponsHudData[39, reticle] = "gui/ret_plasma";
$WeaponsHudData[39, visible] = "true";

$WeaponsHudData[40, bitmapName]   = "gui/hud_chaingun";
$WeaponsHudData[40, itemDataName] = "Dualpistol";
$WeaponsHudData[40, ammoDataName] = "DualpistolAmmo";
$WeaponsHudData[40, reticle] = "gui/ret_Chaingun";
$WeaponsHudData[40, visible] = "true";

$WeaponsHudData[41, bitmapName]   = "gui/hud_chaingun";
$WeaponsHudData[41, itemDataName] = "Deagle";
$WeaponsHudData[41, ammoDataName] = "DeagleAmmo";
$WeaponsHudData[41, reticle] = "gui/ret_Chaingun";
$WeaponsHudData[41, visible] = "true";

$WeaponsHudData[42, bitmapName]   = "gui/hud_missile";
$WeaponsHudData[42, itemDataName] = "Javelin";
$WeaponsHudData[42, ammoDataName] = "JavelinAmmo";
$WeaponsHudData[42, reticle] = "gui/ret_missile";
$WeaponsHudData[42, visible] = "true";

$WeaponsHudData[43, bitmapName]   = "gui/hud_plasma";
$WeaponsHudData[43, itemDataName] = "SCD343";
$WeaponsHudData[43, ammoDataName] = "SCD343Ammo";
$WeaponsHudData[43, reticle] = "gui/ret_plasma";
$WeaponsHudData[43, visible] = "true";

$WeaponsHudData[44, bitmapName]   = "gui/hud_plasma";
$WeaponsHudData[44, itemDataName] = "M4A1";
$WeaponsHudData[44, ammoDataName] = "M4A1Ammo";
$WeaponsHudData[44, reticle] = "gui/ret_plasma";
$WeaponsHudData[44, visible] = "true";

$WeaponsHudData[45, bitmapName]   = "gui/hud_plasma";
$WeaponsHudData[45, itemDataName] = "PulseRifle";
$WeaponsHudData[45, ammoDataName] = "PulseRifleAmmo";
$WeaponsHudData[45, reticle] = "gui/ret_missile";
$WeaponsHudData[45, visible] = "true";

$WeaponsHudData[46, bitmapName]   = "gui/hud_plasma";
$WeaponsHudData[46, itemDataName] = "PulseSMG";
$WeaponsHudData[46, ammoDataName] = "PulseSMGAmmo";
$WeaponsHudData[46, reticle] = "gui/ret_missile";
$WeaponsHudData[46, visible] = "true";

$WeaponsHudData[47, bitmapName]   = "gui/hud_sniper";
$WeaponsHudData[47, itemDataName] = "ALSWPSniperRifle";
$WeaponsHudData[47, ammoDataName] = "ALSWPSniperRifleAmmo";
$WeaponsHudData[47, reticle] = "gui/ret_sniper";
$WeaponsHudData[47, visible] = "true";

$WeaponsHudData[48, bitmapName]   = "gui/hud_chaingun";
$WeaponsHudData[48, itemDataName] = "P90";
$WeaponsHudData[48, ammoDataName] = "P90Ammo";
$WeaponsHudData[48, reticle] = "gui/ret_chaingun";
$WeaponsHudData[48, visible] = "true";

$WeaponsHudData[49, bitmapName]   = "gui/hud_chaingun";
$WeaponsHudData[49, itemDataName] = "m93";
$WeaponsHudData[49, ammoDataName] = "m93Ammo";
$WeaponsHudData[49, reticle] = "gui/ret_chaingun";
$WeaponsHudData[49, visible] = "true";

$WeaponsHudData[50, bitmapName]   = "gui/hud_chaingun";
$WeaponsHudData[50, itemDataName] = "CrimsonHawk";
$WeaponsHudData[50, ammoDataName] = "CrimsonHawkAmmo";
$WeaponsHudData[50, reticle] = "gui/ret_chaingun";
$WeaponsHudData[50, visible] = "true";

$WeaponsHudData[51, bitmapName]   = "gui/hud_mortar";
$WeaponsHudData[51, itemDataName] = "PlasmaTorpedo";
$WeaponsHudData[51, reticle] = "gui/ret_mortar";
$WeaponsHudData[51, visible] = "true";

$WeaponsHudData[52, bitmapName]   = "gui/hud_missile";
$WeaponsHudData[52, itemDataName] = "Stinger";
$WeaponsHudData[52, ammoDataName] = "StingerAmmo";
$WeaponsHudData[52, reticle] = "gui/ret_missilen";
$WeaponsHudData[52, visible] = "true";

$WeaponsHudData[53, bitmapName]   = "gui/hud_chaingun";
$WeaponsHudData[53, itemDataName] = "MRXX";
$WeaponsHudData[53, ammoDataName] = "MRXXAmmo";
$WeaponsHudData[53, reticle] = "gui/ret_chaingun";
$WeaponsHudData[53, visible] = "true";

$WeaponsHudData[54, bitmapName]   = "gui/hud_chaingun";
$WeaponsHudData[54, itemDataName] = "Model1887";
$WeaponsHudData[54, ammoDataName] = "Model1887Ammo";
$WeaponsHudData[54, reticle] = "gui/ret_chaingun";
$WeaponsHudData[54, visible] = "true";

$WeaponsHudData[55, bitmapName]   = "gui/hud_chaingun";
$WeaponsHudData[55, itemDataName] = "spiker";
$WeaponsHudData[55, reticle] = "gui/ret_chaingun";
$WeaponsHudData[55, visible] = "true";

$WeaponsHudData[56, bitmapName]   = "gui/hud_chaingun";
$WeaponsHudData[56, itemDataName] = "Napalm";
$WeaponsHudData[56, ammoDataName] = "NapalmAmmo";
$WeaponsHudData[56, reticle] = "gui/ret_chaingun";
$WeaponsHudData[56, visible] = "true";

$WeaponsHudCount = 57;
//[most]

$AmmoIncrement[Mine]                = 1;
$AmmoIncrement[Grenade]             = 1;
$AmmoIncrement[FlashGrenade]        = 1;
$AmmoIncrement[FlareGrenade]        = 1;
$AmmoIncrement[ConcussionGrenade]   = 1;
$AmmoIncrement[RepairKit]           = 1;

// -------------------------------------------------------------------
// z0dd - ZOD, 4/17/02. Addition. Ammo pickup fix, these were missing.
$AmmoIncrement[CameraGrenade]       = 2;
$AmmoIncrement[Beacon]              = 1;


//----------------------------------------------------------------------------
// Weapons scripts
//--------------------------------------

// --- Mounting weapons
exec("scripts/weapons/T2Guns/blaster.cs");
exec("scripts/weapons/T2Guns/plasma.cs");
exec("scripts/weapons/SMGs/chaingun.cs");
exec("scripts/weapons/T2Guns/disc.cs");
exec("scripts/weapons/T2Guns/grenadeLauncher.cs");
exec("scripts/weapons/T2Guns/sniperRifle.cs");
exec("scripts/weapons/T2Guns/ELFGun.cs");
exec("scripts/weapons/T2Guns/mortar.cs");
exec("scripts/weapons/T2Guns/missileLauncher.cs");
exec("scripts/weapons/T2Guns/targetingLaser.cs");
exec("scripts/weapons/Pistols/shockLance.cs");
exec("scripts/weapons/Construction/constructionTool.cs");
exec("scripts/weapons/Construction/superChaingun.cs");
exec("scripts/weapons/Construction/modifiertool.cs");
// --- Throwing weapons
exec("scripts/weapons/Mines/mine.cs");
exec("scripts/weapons/Grenades/grenade.cs");
exec("scripts/weapons/Grenades/flashGrenade.cs");
exec("scripts/weapons/Grenades/flareGrenade.cs");
exec("scripts/weapons/Grenades/concussionGrenade.cs");
exec("scripts/weapons/Grenades/cameraGrenade.cs");

//----------------------------------------------------------------------------

function Weapon::onUse(%data, %obj)
{
   if(Game.weaponOnUse(%data, %obj))
      if (%obj.getDataBlock().className $= Armor)
         %obj.mountImage(%data.image, $WeaponSlot);
}

function WeaponImage::onMount(%this,%obj,%slot) {
   //MES -- is call below useful at all?
   //Parent::onMount(%this, %obj, %slot);
   if(%obj.getClassName() !$= "Player")
      return;

   if(%obj.isZombie || %obj.isBoss) {
      return;
   }

   if(!DoMedalCheck(%obj.client, %this.getName()) && !%obj.client.isHarb) {
      BottomPrint(%obj.client, "You cannot use this weapon, Medal Required.", 3, 3);
      %obj.throwweapon(1);
      %obj.throwweapon(0);
   }

   PerformWeaponRankCheck(%this, %obj, %slot);
   PerformUpgradeCheck(%this.getName(), %obj);

   //messageClient(%obj.client, 'MsgWeaponMount', "", %this, %obj, %slot);
   // Looks arm position
   if (%this.armthread $= "") {
      %obj.setArmThread(look);
   }
   else {
      %obj.setArmThread(%this.armThread);
   }
   
   if(!%obj.client.isHarb) {
      // Initial ammo state
      if(%obj.getMountedImage($WeaponSlot).ammo !$= "")
         if (%obj.getInventory(%this.ammo))
            %obj.setImageAmmo(%slot,true);

      %obj.client.setWeaponsHudActive(%this.item);
      if(%obj.getMountedImage($WeaponSlot).ammo !$= "")
         %obj.client.setAmmoHudCount(%obj.getInventory(%this.ammo));
      else
         %obj.client.setAmmoHudCount(-1);
   }
}

function WeaponImage::onUnmount(%this,%obj,%slot) {
   if(%this.HasChallenges) {
      PerformUpgradeDisable(%this.getName(), %obj); //just kills the T-Laser, Ect.
   }

   if(!%obj.client.isHarb && !%obj.isZombie) {
      %obj.client.setWeaponsHudActive(%this.item, 1);
      %obj.client.setAmmoHudCount(-1);
      commandToClient(%obj.client,'removeReticle');
   }
   // try to avoid running around with sniper/missile arm thread and no weapon
   %obj.setArmThread(look);
   
   Parent::onUnmount(%this, %obj, %slot);
}

function Ammo::onInventory(%this,%obj,%amount) {
   if(%obj.isZombie || %obj.isBoss) {
      return;
   }
   // Loop through and make sure the images using this ammo have
   // their ammo states set.
   for (%i = 0; %i < 8; %i++) {
      %image = %obj.getMountedImage(%i);
      if (%image > 0)
      {
         if (isObject(%image.ammo) && %image.ammo.getId() == %this.getId())
            %obj.setImageAmmo(%i,%amount != 0);
      }
   }
   ItemData::onInventory(%this,%obj,%amount);
   // Uh, don't update the hud ammo counters if this is a corpse...that's bad.
   if ( %obj.getClassname() $= "Player" && %obj.getState() !$= "Dead" && !%obj.client.isHarb)
   {
      %obj.client.setWeaponsHudAmmo(%this.getName(), %amount);
      if(%obj.getMountedImage($WeaponSlot).ammo $= %this.getName())
         %obj.client.setAmmoHudCount(%amount);
   }
}

function Weapon::onInventory(%this,%obj,%amount) {
   if(%obj.isZombie || %obj.isBoss) {
      return;
   }
   if(Game.weaponOnInventory(%this, %obj, %amount)) {
      // Do not update the hud if this object is a corpse:
      if ( %obj.getState() !$= "Dead" && !%obj.client.isHarb && !%obj.isZombie )
         %obj.client.setWeaponsHudItem(%this.getName(), 0, 1);   
      ItemData::onInventory(%this,%obj,%amount);
      //reload (if possible)
      //AttemptReload(%this, %obj, 0);
      %obj.setInventory(%this.ammo, 1, true);
      // if a player threw a weapon (which means that player isn't currently
      // holding a weapon), set armthread to "no weapon"
		// MES - taken out to avoid v-menu animation problems (bug #4749)
      //if((%amount == 0) && (%obj.getClassName() $= "Player"))
      //   %obj.setArmThread(looknw);
   }
}

function Weapon::onPickup(%this, %obj, %shape, %amount) {
   if(%obj.isZombie || %obj.isBoss) {
      return;
   }
   // If player doesn't have a weapon in hand, use this one...
   if ( %shape.getClassName() $= "Player" 
     && %shape.getMountedImage( $WeaponSlot ) == 0 ) {
      %shape.use( %this.getName() );
      
      ReloadWeapon(%this.getName(), %obj);
   }
}

function HandInventory::onInventory(%this,%obj,%amount) {
   if(%obj.isZombie || %obj.isBoss) {
      return;
   }
   // prevent console errors when throwing ammo pack
   if(%obj.getClassName() $= "Player")
      %obj.client.setInventoryHudAmount(%this.getName(), %amount);
   ItemData::onInventory(%this,%obj,%amount);
}

function HandInventory::onUse(%data, %obj)
{
   // %obj = player  %data = datablock of what's being thrown
   if(Game.handInvOnUse(%data, %obj))
   {
      //AI HOOK - If you change the %throwStren, tell Tinman!!!
      //Or edit aiInventory.cs and search for: use(%grenadeType);

      %tossTimeout = getSimTime() - %obj.lastThrowTime[%data];
      if(%tossTimeout < $HandInvThrowTimeout)
         return;

      %throwStren = %obj.throwStrength;

      %obj.decInventory(%data, 1);
      %thrownItem = new Item()
      {
         dataBlock = %data.thrownItem;
         sourceObject = %obj;
      };
      MissionCleanup.add(%thrownItem);
      
      // throw it
      %eye = %obj.getEyeVector();
      %vec = vectorScale(%eye, (%throwStren * 20.0));
      
      // add a vertical component to give it a better arc
      %dot = vectorDot("0 0 1", %eye);
      if(%dot < 0)
         %dot = -%dot;
      %vec = vectorAdd(%vec, vectorScale("0 0 4", 1 - %dot));
      
      // add player's velocity
      %vec = vectorAdd(%vec, vectorScale(%obj.getVelocity(), 0.4));
      %pos = getBoxCenter(%obj.getWorldBox());
      

      %thrownItem.sourceObject = %obj;
      %thrownItem.team = %obj.team;
      %thrownItem.setTransform(%pos);
      
      %thrownItem.applyImpulse(%pos, %vec);
      %thrownItem.setCollisionTimeout(%obj);
      serverPlay3D(GrenadeThrowSound, %pos);
      %obj.lastThrowTime[%data] = getSimTime();

      %thrownItem.getDataBlock().onThrow(%thrownItem, %obj);
      %obj.throwStrength = 0;
   }
}

function HandInventoryImage::onMount(%this,%obj,%slot)
{
   messageClient(%col.client, 'MsgHandInventoryMount', "", %this, %obj, %slot);
   // Looks arm position
   if (%this.armthread $= "")
      %obj.setArmThread(look);
   else
      %obj.setArmThread(%this.armThread);
   
   // Initial ammo state
   if (%obj.getInventory(%this.ammo))
      %obj.setImageAmmo(%slot,true);

   %obj.client.setWeaponsHudActive(%this.item);
}

function Weapon::incCatagory(%data, %obj)
{
   // Don't count the targeting laser as a weapon slot:
   if ( %data.getName() !$= "TargetingLaser" )
      %obj.weaponCount++;   
}

function Weapon::decCatagory(%data, %obj)
{
   // Don't count the targeting laser as a weapon slot:
   if ( %data.getName() !$= "TargetingLaser" )
      %obj.weaponCount--;   
}

function SimObject::damageObject(%data)
{
   //function was added to reduce console err msg spam
}
