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

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

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

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

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

$WeaponsHudData[4, bitmapName] = "gui/hud_sniper";
$WeaponsHudData[4, itemDataName] = "LMissileLauncher";
$WeaponsHudData[4, ammoDataName] = "LMissileLauncherAmmo";
$WeaponsHudData[4, reticle] = "gui/hud_ret_sniper";
$WeaponsHudData[4, visible] = "true";

$WeaponsHudData[5, bitmapName] = "gui/hud_sniper";
$WeaponsHudData[5, itemDataName] = "snipergun";
$WeaponsHudData[5, ammoDataName] = "snipergunammo";
$WeaponsHudData[5, reticle] = "gui/hud_ret_sniper";
$WeaponsHudData[5, visible] = "true";

$WeaponsHudData[6, bitmapName] = "gui/hud_missiles";
$WeaponsHudData[6, itemDataName] = "Bazooka";
$WeaponsHudData[6, ammoDataName] = "BazookaAmmo";
$WeaponsHudData[6, reticle] = "gui/ret_missile";
$WeaponsHudData[6, visible] = "true";

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

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

$WeaponsHudData[9, bitmapName] = "gui/hud_shocklance";
$WeaponsHudData[9, itemDataName] = "KriegRifle";
$WeaponsHudData[9, ammoDataName] = "RifleClip";
$WeaponsHudData[9, reticle] = "gui/hud_ret_shocklance";
$WeaponsHudData[9, visible] = "true";

$WeaponsHudData[10, bitmapName] = "gui/hud_missiles";
$WeaponsHudData[10, itemDataName] = "RailGun";
$WeaponsHudData[10, ammoDataName] = "RailGunAmmo";
$WeaponsHudData[10, reticle] = "gui/ret_missile";
$WeaponsHudData[10, visible] = "true";

$WeaponsHudData[11, bitmapName] = "gui/hud_missiles";
$WeaponsHudData[11, itemDataName] = "AALauncher";
$WeaponsHudData[11, ammoDataName] = "AALauncherAmmo";
$WeaponsHudData[11, reticle] = "gui/ret_missile";
$WeaponsHudData[11, visible] = "true";

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

$WeaponsHudData[13, bitmapName] = "gui/hud_chaingun";
$WeaponsHudData[13, itemDataName] = "RShotgun";
$WeaponsHudData[13, ammoDataName] = "RShotgunClip";
$WeaponsHudData[13, reticle] = "gui/ret_chaingun";
$WeaponsHudData[13, visible] = "true";

$WeaponsHudData[14, bitmapName] = "gui/hud_chaingun";
$WeaponsHudData[14, itemDataName] = "HRPChaingun";
$WeaponsHudData[14, ammoDataName] = "HRPChaingunClip";
$WeaponsHudData[14, reticle] = "gui/ret_chaingun";
$WeaponsHudData[14, visible] = "true";

$WeaponsHudData[15, bitmapName] = "gui/hud_chaingun";
$WeaponsHudData[15, itemDataName] = "LSMG";
$WeaponsHudData[15, ammoDataName] = "LSMGClip";
$WeaponsHudData[15, reticle] = "gui/ret_chaingun";
$WeaponsHudData[15, visible] = "true";

$WeaponsHudData[16, bitmapName]   = "gui/hud_shocklance";
$WeaponsHudData[16, itemDataName] = "MergeTool";
$WeaponsHudData[16, reticle] = "gui/hud_ret_sniper";
$WeaponsHudData[16, visible] = "true";

$WeaponsHudData[17, bitmapName] = "gui/hud_sniper";
$WeaponsHudData[17, itemDataName] = "PBC";
$WeaponsHudData[17, ammoDataName] = "PBCAmmo";
$WeaponsHudData[17, reticle] = "gui/hud_ret_sniper";
$WeaponsHudData[17, visible] = "true";

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

$WeaponsHudData[19, bitmapName] = "gui/hud_plasma";
$WeaponsHudData[19, itemDataName] = "NapalmMortar";
$WeaponsHudData[19, ammoDataName] = "NapalmAmmo";
$WeaponsHudData[19, reticle] = "gui/ret_mortor";
$WeaponsHudData[19, visible] = "true";

$WeaponsHudData[20, bitmapName] = "gui/hud_plasma";
$WeaponsHudData[20, itemDataName] = "LordAcidGun";
$WeaponsHudData[20, reticle] = "gui/ret_grenade";
$WeaponsHudData[20, visible] = "true";

$WeaponsHudData[21, bitmapName] = "gui/hud_grenlaunch";
$WeaponsHudData[21, itemDataName] = "M4";
$WeaponsHudData[21, ammoDataName] = "RifleClip";
$WeaponsHudData[21, reticle] = "gui/ret_grenade";
$WeaponsHudData[21, visible] = "true";

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


$WeaponsHudCount = 23;
//[most]

$AmmoIncrement[PlasmaAmmo]          = 10;
$AmmoIncrement[ChaingunAmmo]        = 500;
$AmmoIncrement[DiscAmmo]            = 5;
$AmmoIncrement[GrenadeLauncherAmmo] = 5;
$AmmoIncrement[MortarAmmo]          = 5;
$AmmoIncrement[MissileLauncherAmmo] = 2;
$AmmoIncrement[Mine]                = 3;
$AmmoIncrement[Grenade]             = 5;
$AmmoIncrement[FlashGrenade]        = 5;
$AmmoIncrement[FlareGrenade]        = 5;
$AmmoIncrement[ConcussionGrenade]   = 5;
$AmmoIncrement[RepairKit]           = 1;

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

$AmmoIncrement[RPChaingunAmmo] = 30;
$AmmoIncrement[MGClip] = 1;
$AmmoIncrement[snipergunAmmo] = 10;
$AmmoIncrement[BazookaAmmo] = 5;
$AmmoIncrement[MG42Ammo] = 200;
$AmmoIncrement[MG42Clip] = 1;
$AmmoIncrement[flamerAmmo] = 25;
$AmmoIncrement[AALauncherAmmo] = 1;
$AmmoIncrement[KriegAmmo] = 10;
$AmmoIncrement[RifleClip] = 1;
$AmmoIncrement[ShotgunAmmo] = 8;
$AmmoIncrement[ShotgunClip] = 1;
$AmmoIncrement[RShotgunAmmo] = 25;
$AmmoIncrement[RShotgunClip] = 1;
$AmmoIncrement[LMissileLauncherAmmo] = 1;
$AmmoIncrement[RPGAmmo] = 1;
$AmmoIncrement[SmokeGrenade]= 5;
$AmmoIncrement[BeaconSmokeGrenade]= 2;
$AmmoIncrement[LSMGAmmo] = 60;
$AmmoIncrement[LSMGClip] = 1;
$AmmoIncrement[PBCAmmo] = 1;
$AmmoIncrement[NapalmAmmo] = 2;
$AmmoIncrement[RailGunAmmo] = 2;
$AmmoIncrement[M4Ammo] = 4;


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

// --- Mounting weapons
exec("scripts/weapons/allweapons.cs");
exec("scripts/weapons/missileLauncher.cs");
exec("scripts/weapons/targetingLaser.cs");
exec("scripts/weapons/shockLance.cs");
exec("scripts/weapons/constructionTool.cs");
exec("scripts/weapons/superChaingun.cs");
exec("scripts/weapons/RPChaingun.cs");
exec("scripts/weapons/snipergun.cs");
exec("scripts/weapons/bazooka.cs");
exec("scripts/weapons/MG42.cs");
exec("scripts/weapons/railgun.cs");
exec("scripts/weapons/flamethrower.cs");
exec("scripts/weapons/rocketLauncher.cs");
exec("scripts/weapons/Krieg.cs");
exec("scripts/weapons/Shotgun.cs");
exec("scripts/weapons/FlameMortar.cs");
exec("scripts/weapons/LightMachineGun.cs");
exec("scripts/weapons/mergetool.cs");
exec("scripts/weapons/EditingTool.cs");
exec("scripts/weapons/TextureTool.cs");
exec("scripts/weapons/ZLordPoison.cs");
exec("scripts/weapons/PBC.cs");
exec("scripts/weapons/mine.cs");
exec("scripts/weapons/M4GrenadeLauncher.cs");
exec("scripts/weapons/grenade.cs");
exec("scripts/weapons/Smokegrenade.cs");
exec("scripts/weapons/flashGrenade.cs");
exec("scripts/weapons/flareGrenade.cs");
exec("scripts/weapons/concussionGrenade.cs");
exec("scripts/weapons/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;

   //messageClient(%obj.client, 'MsgWeaponMount', "", %this, %obj, %slot);
   // Looks arm position
   if (%this.armthread $= "")
   {
      %obj.setArmThread(look);
   }
   else
   {
      %obj.setArmThread(%this.armThread);
   }

   // 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)
{
   %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)
{
   // 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.setWeaponsHudAmmo(%this.getName(), %amount);
      if(%obj.getMountedImage($WeaponSlot).ammo $= %this.getName())
         %obj.client.setAmmoHudCount(%amount);
   }
}

function Weapon::onInventory(%this,%obj,%amount)
{
   if(Game.weaponOnInventory(%this, %obj, %amount))
   {
      // Do not update the hud if this object is a corpse:
      if ( %obj.getState() !$= "Dead" )
         %obj.client.setWeaponsHudItem(%this.getName(), 0, 1);
      ItemData::onInventory(%this,%obj,%amount);
      // 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 player doesn't have a weapon in hand, use this one...
   if ( %shape.getClassName() $= "Player" && %shape.getMountedImage( $WeaponSlot ) == 0 )
      %shape.use( %this.getName() );
}

function HandInventory::onInventory(%this,%obj,%amount)
{
   // 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
}

