
datablock ShapeBaseImageData(TAGPackExtra)
{
   shapeFile = "weapon_missile_casement.dts";
   mountPoint = 2;
   offset = "-0.35 0 0.4";
   rotation = "-1 0.5 0 90";
   emap = true;
};

datablock ShapeBaseImageData(TAGPackImage)
{
   shapeFile = "ammo_chaingun.dts";
   item = TAG;
   mountPoint = 2;
   offset = "0 0 -0.16";
   emap = true;

   mass = 3.4;

   gun = TAGGunImage;

   stateName[0] = "Idle";
   stateTransitionOnTriggerDown[0] = "Activate";

   stateName[1] = "Activate";
   stateScript[1] = "onActivate";
   stateSequence[1] = "fire";
   stateSound[1] = RepairPackActivateSound;
   stateTransitionOnTriggerUp[1] = "Deactivate";

   stateName[2] = "Deactivate";
   stateScript[2] = "onDeactivate";
   stateTransitionOnTimeout[2] = "Idle";   
};

datablock ItemData(TAG)
{
   className = Pack;
   catagory = "Packs";
   shapeFile = "ammo_chaingun.dts";
   mass = 3;
   elasticity = 0.2;
   friction = 0.6;
   pickupRadius = 2;

   image = "TAGPackImage";
   pickUpName = "a Target Acquisition pack";

   computeCRC = true;
   emap = true;
};

datablock TargetProjectileData(TAGTargeter)
{
   directDamage         = 0.0;
   hasDamageRadius      = false;
   indirectDamage       = 0.0;
   damageRadius         = 0.0;
   velInheritFactor     = 1.0;

   maxRifleRange        = 1000;
   beamColor            = "1.0 1.0 1.0";
                        
   startBeamWidth       = 0.0;
   pulseBeamWidth       = 0.0;
   beamFlareAngle       = 0.0;
   minFlareSize         = 0.0;
   maxFlareSize         = 0.0;
   pulseSpeed           = 0.0;
   pulseLength          = 0.0;

   textureName[0]       = "special/nonlingradient";
   textureName[1]       = "special/flare";
   textureName[2]       = "special/pulse";
   textureName[3]      	= "special/expFlare";
   beacon               = true;
   beaconType           = vehicle;
};

datablock ShapeBaseImageData(TAGGunImage)
{
   className = WeaponImage;

   shapeFile = "weapon_targeting.dts";
   offset = "0 0 0";

   item = TAG;
   image = TAGPackImage;

   projectile = TAGTargeter;
   projectileType = TargetProjectile;
   deleteLastProjectile = true;

   usesEnergy = true;
   minEnergy = 5;

   stateName[0]                = "Activate";
   stateSequence[0]            = "Activate";
   stateSound[0]               = BomberTargetingSwitchSound;
   stateTimeoutValue[0]        = 0.5;
   stateTransitionOnTimeout[0] = "ActivateReady";

   stateName[1]               = "ActivateReady";
   stateTransitionOnAmmo[1]   = "Ready";
   stateTransitionOnNoAmmo[1] = "NoAmmo";

   stateName[2]                    = "Ready";
   stateTransitionOnNoAmmo[2]      = "NoAmmo";
   stateTransitionOnTriggerDown[2] = "Fire";

   stateName[3]                  = "Fire";
   stateEnergyDrain[3]           = 3;
   stateFire[3]                  = true;
   stateAllowImageChange[3]      = false;
   stateScript[3]                = "onFire";
   stateTransitionOnTriggerUp[3] = "Deconstruction";
   stateTransitionOnNoAmmo[3]    = "Deconstruction";
   stateSound[3] = BomberTargetingPaintSound;

   stateName[4]                = "NoAmmo";
   stateTransitionOnAmmo[4]    = "Ready";

   stateName[5]                = "Deconstruction";
   stateTransitionOnTimeout[5] = "ActivateReady";
   stateTimeoutValue[5]        = 0.05;
   stateScript[5]              = "deconstruct";
};

function TAGGunImage::onFire(%data, %Player, %Slot)
{
   if (%Player.beacon !$= "")
   {
      %Player.beacon.delete();
      %Player.beacon = "";
   }   
   %Projectile = Parent::onFire(%data, %Player, %Slot);
   %Projectile.setTarget(%Player.team);
}

function TAGGunImage::deconstruct(%data, %Player, %Slot)
{
   echo("Player: " @ %Player);
   %Position = %Player.lastProjectile.getTargetPoint();
   
   if (%Player.beacon !$= "")
      %Player.beacon.delete();

   %Player.beacon = new BeaconObject()
   {
      dataBlock = "BomberBeacon";
      beaconType = "vehicle";
      position = %Position;
   };

   %Player.beacon.playThread($AmbientThread, "ambient");
   %Player.beacon.team = %Vehicle.team;
   %Player.beacon.sourceObject = %Player;

   // give it a team target
   %Player.beacon.setTarget(%Player.team);
   BeaconGroup.add(%Player.beacon);
   
   Parent::deconstruct(%data, %Player, %Slot);
}

function TAGPackImage::onUnmount(%data, %Player, %node)
{
   // dismount the TAG gun if the player had it mounted
   // need the extra "if" statement to avoid crashing
   if(%Player.getMountedImage($WeaponSlot))
      if(%Player.getMountedImage($WeaponSlot).getName() $= "TAGGunImage")
         %Player.unmountImage($WeaponSlot);

   %Player.unMountImage(6);

   // Since the TAG is off, remove the beacon
   if(%Player.beacon !$= "")
   {
      %Player.beacon.delete();
      %Player.beacon = "";
   }
}

function TAGPackImage::onMount(%data, %Player, %node)
{
   %Player.MountImage("TAGPackExtra", 6);
}

function TAGPackImage::onActivate(%data, %Player, %Slot)
{
   // don't activate the pack if player is piloting a vehicle
   if(%Player.isPilot())
   {
      %Player.setImageTrigger(%Slot, false);
      return;
   }

   if(!isObject(%Player.getMountedImage($WeaponSlot)) || %Player.getMountedImage($WeaponSlot).getName() !$= "TAGGunImage")
   {
      %Client = %Player.client;

      messageClient(%Client, 'MsgRepairPackOn', '\c2Target Acquistion Gear Activated.');

      // unmount any weapon the player may have been holding
      if(%Player.getMountedImage($WeaponSlot))
         %Player.unmountImage($WeaponSlot);

      // make sure player's arm thread is "look"
      %Player.setArmThread(look);

      // mount the repair gun
      %Player.mountImage(TAGGunImage, $WeaponSlot);

      // clientCmdsetRepairReticle found in hud.cs
      commandToClient(%Client, 'setRepairReticle');

      // If the player wants to see help, bottom print it for them.
      if (%Client.ShowHelp == true)
      {
         if (%Client.HelpSchedule !$= "")
            Cancel(%Client.HelpSchedule);

         %Message = $HelpDesc[TAGGunImage];
         %Lines = $HelpLines[TAGGunImage];
         if (%Message $= "")
            return;

         bottomPrint(%Client, %Message, 10, %Lines);
      
         %Client.HelpSchedule = schedule(%Lines * 6000, %Client, clearBottomPrint, %Client);
      }
   }
}

//called when the player hits the "pack" key again
function TAGPackImage::onDeactivate(%data, %Player, %Slot)
{
   %Player.setImageTrigger(%Slot, false);

   // Since the TAG is off, remove the beacon
   if(%Player.beacon !$= "")
   {
      %Player.beacon.delete();
      %Player.beacon = "";
   }
 
   // if TAG gun was mounted, unmount it
   if(%Player.getMountedImage($WeaponSlot).getName() $= "TAGGunImage")
      %Player.unmountImage($WeaponSlot);
}

function TAGGunImage::onMount(%this, %Player, %Slot)
{
   %Player.setImageAmmo(%Slot,true);
}

// called when player switches to another weapon
function TAGGunImage::onUnmount(%this, %Player, %Slot)
{
   // Since the TAG is off, remove the beacon
   if(%Player.beacon !$= "")
   {
      %Player.beacon.delete();
      %Player.beacon = "";
   }

   %Player.setImageTrigger(%Slot, false);

   // "turn off" the TAG pack -- player needs to hit the "pack" key to
   // activate the TAG gun again
   %Player.setImageTrigger($BackpackSlot, false);
}

function TAGPackImage::onPickup(%this, %Player, %Shape, %Amount)
{
   // created to prevent console errors
}