//PER-KR'S CHAINGUN.
//bondo decompiled this code with permission
void () hcg_precache = {

   precache_sound ("chaingun/fire.wav");
   precache_sound ("chaingun/engine1.wav");
   precache_sound ("chaingun/engine2.wav");
   precache_sound ("chaingun/engine3.wav");
   precache_sound ("chaingun/ric1.wav");
   precache_sound ("chaingun/ric2.wav");
   precache_sound ("chaingun/click.wav");
   precache_sound ("chaingun/reload.wav");
   precache_sound ("chaingun/gib1.wav");
   precache_sound ("chaingun/gib2.wav");
   precache_sound ("chaingun/gib3.wav");
   precache_sound ("chaingun/gib4.wav");
   precache_sound ("chaingun/shell1.wav");
   precache_sound ("chaingun/shell2.wav");
   precache_model ("progs/v_hcg.mdl");
   precache_model ("progs/shelcase.mdl");
   precache_model ("progs/bultcase.mdl");

};

void () player_chaingunb1;

void () player_chaingun1;

void () ShellTouch = {


	{
	   if ( (random () < 0.500) ) {

      sound (self,CHAN_WEAPON,"chaingun/shell1.wav",1.000,ATTN_NORM);

   } else {

      if ( (random () < 0.500) ) {

         sound (self,CHAN_WEAPON,"chaingun/shell2.wav",1.000,ATTN_NORM);

      }

   }
   }
   if ( (self.velocity == '0.000 0.000 0.000') ) {

      self.avelocity = '0.000 0.000 0.000';

   }

};

void (vector org, vector vel, float damage) SpawnBlood;

//void () player_shotc0;

/*
void () WeaponSelect = {


	if ( (self.weapon == IT_SUPER_NAILGUN) && ((self.supernailguntype == 0) || (self.supernailguntype ==4 )) )
               {

                     if ( (self.ammo_nails < 2.000) )
                     {

                        player_chaingunb1 ();

                     }
                     else
                     {

                        player_chaingun1 ();

                     }
               }
	else if (self.weapon == IT_SUPER_SHOTGUN && (self.supershotguntype == 4))
   	player_shotc0 ();
          



};
*/

void (vector dir) ricsound = {

   local entity hit;

   hit = spawn ();
   hit.origin = (trace_endpos - (dir * 4.000));
   if ( (random () < 0.500) ) {

      if ( (random () < 0.500) ) {

         sound (hit,CHAN_WEAPON,"chaingun/ric1.wav",1.000,ATTN_IDLE);

      } else {

         sound (hit,CHAN_WEAPON,"chaingun/ric2.wav",1.000,ATTN_IDLE);

      }

   }
   hit.think = SUB_Remove;
   hit.nextthink = (time + 0.000);

};

void (vector org, vector vel) Bullet = {

   local entity shell;
   local entity mpuff;

   shell = spawn ();
   shell.owner = self;
   shell.movetype = MOVETYPE_BOUNCE;
   shell.solid = SOLID_BBOX;
   makevectors (self.angles);
   shell.velocity = vel;
   shell.velocity_z = ((shell.velocity_z + 180.000) + (40.000 * random ()));
   shell.avelocity = '1000.000 1000.000 1000.000';
   shell.touch = ShellTouch;
   shell.nextthink = (time + 1.000); //was time + 1
   shell.think = SUB_Remove;
   //setmodel (shell,"progs/shell.mdl");
   if (self.weapon > IT_SUPER_SHOTGUN)
	   setmodel (shell,"progs/bultcase.mdl");
	else
	   setmodel (shell,"progs/shelcase.mdl");
   setsize (shell,'0.000 0.000 0.000','0.000 0.000 0.000');
   setorigin (shell,org);

};

void (float shotcount, vector dir, vector spread) FireBullets;

void () W_FireChaingun = {

   local vector dir;
   local entity old;

   if ( (self.ammo_nails < 2.000) ) {

      return ;

   }

	   sound (self,CHAN_VOICE,"chaingun/fire.wav",1.000,ATTN_NORM);

   dir = aim (self,100000.000);

	if (self.supernailguntype == 0)
	{
	   FireBullets (5.000,dir,'0.160 0.120 0.000');
      self.ammo_nails = (self.ammo_nails - 1.5);
      self.currentammo = (self.ammo_nails - 1.5);
   }
	   
	else {
      self.ammo_nails = (self.ammo_nails - 2);
      self.currentammo = (self.ammo_nails - 2);
	   FireBullets (1.000,dir,'0.200 0.120 0.000');
	  }

   self.effects = (self.effects | EF_MUZZLEFLASH);
   if (!(deathmatch) && !(coop))
	   Bullet (((self.origin + (v_forward * 16.000)) + (v_right * 6.000)),(v_right * 32.000));

};

void () W_FireNoAmmo = {

   local vector source;
   local vector org;


	   sound (self,CHAN_VOICE,"chaingun/click.wav",1.000,ATTN_NORM);
   source = (self.origin + '0.000 0.000 16.000');
   traceline (source,(source + (v_forward * 64.000)),FALSE,self);
   if ( (trace_fraction == 1.000) ) {

      return ;

   }
   org = (trace_endpos - (v_forward * 4.000));
   if ( trace_ent.takedamage ) {

      trace_ent.axhitme = 1.000;
      SpawnBlood (org,'0.000 0.000 0.000',16.000);
      T_Damage (trace_ent,self,self,12.000);
      if ( (random () < 0.500) ) {

         sound (self,CHAN_BODY,"chaingun/gib1.wav",1.000,ATTN_NORM);

      } else {

         if ( (random () < 0.500) ) {

            sound (self,CHAN_BODY,"chaingun/gib2.wav",1.000,ATTN_NORM);

         } else {

            if ( (random () < 0.500) ) {

               sound (self,CHAN_BODY,"chaingun/gib3.wav",1.000,ATTN_NORM);

            } else {

               sound (self,CHAN_BODY,"chaingun/gib4.wav",1.000,ATTN_NORM);

            }

         }

      }

   } else {

      return ;

   }

};

//revving anim
void () player_cgun1 = [ 12.000, player_cgun2 ] {

   self.weaponframe = 40.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

	   sound (self,CHAN_WEAPON,"chaingun/engine1.wav",1.000,ATTN_NORM);

};

void () player_cgun2 = [ 12.000, player_cgun3 ] {

   self.weaponframe = 41.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgun3 = [ 13.000, player_cgun4 ] {

   self.weaponframe = 42.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgun4 = [ 13.000, player_cgun5 ] {

   self.weaponframe = 43.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgun5 = [ 14.000, player_cgun6 ] {

   self.weaponframe = 44.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgun6 = [ 14.000, player_cgun7 ] {

   self.weaponframe = 45.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgun7 = [ 15.000, player_cgun8 ] {

   self.weaponframe = 104.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgun8 = [ 15.000, player_cgun9 ] {

   self.weaponframe = 47.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgun9 = [ 16.000, player_cgun10 ] {

   self.weaponframe = 48.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgun10 = [ 16.000, player_cgun11 ] {

   self.weaponframe = 49.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgun11 = [ 12.000, player_cgun12 ] {

   self.weaponframe = 50.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgun12 = [ 12.000, player_cgun13 ] {

   self.weaponframe = 51.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgun13 = [ 13.000, player_cgun14 ] {

   self.weaponframe = 34.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgun14 = [ 13.000, player_cgun15 ] {

   self.weaponframe = 35.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgun15 = [ 14.000, player_cgun16 ] {

   self.weaponframe = 36.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgun16 = [ 14.000, player_cgun17 ] {

   self.weaponframe = 37.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgun17 = [ 15.000, player_cgun18 ] {

   self.weaponframe = 38.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);
   //self.chaingun = 1.000;
   self.bondoflag = self.bondoflag | B_CHAINGUN;

};

void () player_cgun18 = [ 15.000, player_cguna7 ] {

   self.weaponframe = 39.000;
   self.nextthink = (time + 0.010);

};

void () player_cguna7;

//firing anim
void () player_cguna1 = [ 103.000, player_cguna2 ] {

   self.weaponframe = 1.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);
   W_FireChaingun ();

};

void () player_cguna2 = [ 104.000, player_cguna3 ] {

   self.weaponframe = 2.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cguna3 = [ 103.000, player_cguna4 ] {

   self.weaponframe = 3.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);
   W_FireChaingun ();

};

void () player_cguna4 = [ 104.000, player_cguna5 ] {

   self.weaponframe = 4.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cguna5 = [ 103.000, player_cguna6 ] {

   self.weaponframe = 5.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);
   W_FireChaingun ();

};

void () player_cguna6 = [ 104.000, player_cguna7 ] {

   self.weaponframe = 6.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cguna7 = [ 103.000, player_cguna8 ] {

   self.weaponframe = 34.000;
   self.nextthink = (time + 0.010);

};

void () player_cguna8 = [ 104, player_cguna9 ] {

   self.weaponframe = 35.000;
   self.nextthink = (time + 0.010);
   //self.chaingun = 0.000;
   self.bondoflag = self.bondoflag - B_CHAINGUN;

	   sound (self,CHAN_WEAPON,"chaingun/engine3.wav",1.000,ATTN_NORM);

};

void () player_cguna9 = [ 103, player_cguna10 ] {

   self.weaponframe = 36.000;
   self.nextthink = (time + 0.010);

};

void () player_cguna10 = [ 104, player_cguna11 ] {

   self.weaponframe = 37.000;
   self.nextthink = (time + 0.010);

};

void () player_cguna11 = [ 103, player_cguna12 ] {

   self.weaponframe = 38.000;
   self.nextthink = (time + 0.010);

};

void () player_cguna12 = [ 104, player_cguna13 ] {

   self.weaponframe = 39.000;
   self.nextthink = (time + 0.010);

};

void () player_cguna13 = [ 103, player_cguna14 ] {

   self.weaponframe = 40.000;
   self.nextthink = (time + 0.010);

};

void () player_cguna14 = [ 104, player_cguna15 ] {

   self.weaponframe = 41.000;
   self.nextthink = (time + 0.010);

};

void () player_cguna15 = [ 103, player_cguna16 ] {

   self.weaponframe = 42.000;
   self.nextthink = (time + 0.010);

};

void () player_cguna16 = [ 104, player_cguna17 ] {

   self.weaponframe = 43.000;
   self.nextthink = (time + 0.010);

};

void () player_cguna17 = [ 103, player_cguna18 ] {

   self.weaponframe = 44.000;
   self.nextthink = (time + 0.010);

};

void () player_cguna18 = [ 104, player_cguna19 ] {

   self.weaponframe = 45.000;
   self.nextthink = (time + 0.010);

};

void () player_cguna19 = [ 103, player_cguna20 ] {

   self.weaponframe = 46.000;
   self.nextthink = (time + 0.010);

};

void () player_cguna20 = [ 104, player_cguna21 ] {

   self.weaponframe = 47.000;
   self.nextthink = (time + 0.010);

};

void () player_cguna21 = [ 103, player_cguna22 ] {

   self.weaponframe = 48.000;
   self.nextthink = (time + 0.010);

};

void () player_cguna22 = [ 104, player_cguna23 ] {

   self.weaponframe = 49.000;
   self.nextthink = (time + 0.010);

};

void () player_cguna23 = [ 103, player_cguna24 ] {

   self.weaponframe = 50.000;
   self.nextthink = (time + 0.010);

};

void () player_cguna24 = [ 104, player_run ] {

   self.weaponframe = 51.000;
   self.nextthink = (time + 0.010);

};

void () player_cgunb1 = [ 103, player_cgunb2 ] {

   self.weaponframe = 52.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

	   sound (self,CHAN_WEAPON,"chaingun/engine1.wav",1.000,ATTN_NORM);

};

void () player_cgunb2 = [ 104, player_cgunb3 ] {

   self.weaponframe = 53.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgunb3 = [ 103, player_cgunb4 ] {

   self.weaponframe = 54.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgunb4 = [ 104, player_cgunb5 ] {

   self.weaponframe = 55.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgunb5 = [ 103, player_cgunb6 ] {

   self.weaponframe = 56.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgunb6 = [ 104, player_cgunb7 ] {

   self.weaponframe = 57.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgunb7 = [ 103, player_cgunb8 ] {

   self.weaponframe = 58.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgunb8 = [ 104, player_cgunb9 ] {

   self.weaponframe = 59.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgunb9 = [ 103, player_cgunb10 ] {

   self.weaponframe = 60.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgunb10 = [ 104, player_cgunb11 ] {

   self.weaponframe = 61.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgunb11 = [ 103, player_cgunb12 ] {

   self.weaponframe = 62.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgunb12 = [ 104, player_cgunb13 ] {

   self.weaponframe = 63.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgunb13 = [ 103, player_cgunb14 ] {

   self.weaponframe = 7.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgunb14 = [ 104, player_cgunb15 ] {

   self.weaponframe = 8.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgunb15 = [ 103, player_cgunb16 ] {

   self.weaponframe = 9.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgunb16 = [ 104, player_cgunb17 ] {

   self.weaponframe = 10.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgunb17 = [ 103, player_cgunb18 ] {

   self.weaponframe = 11.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);
   self.bondoflag = self.bondoflag | B_CHAINGUN;

};

void () player_cgunb18 = [ 104, player_cgunc7 ] {

   self.weaponframe = 12.000;
   self.nextthink = (time + 0.010);

};

void () player_cgunc7;

void () player_cgunc1 = [ 103, player_cgunc2 ] {

   self.weaponframe = 7.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);
   W_FireNoAmmo ();

};

void () player_cgunc2 = [ 104, player_cgunc3 ] {

   self.weaponframe = 8.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgunc3 = [ 103, player_cgunc4 ] {

   self.weaponframe = 9.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);
   W_FireNoAmmo ();

};

void () player_cgunc4 = [ 104, player_cgunc5 ] {

   self.weaponframe = 10.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgunc5 = [ 103, player_cgunc6 ] {

   self.weaponframe = 11.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);
   W_FireNoAmmo ();

};

void () player_cgunc6 = [ 104, player_cgunc7 ] {

   self.weaponframe = 12.000;
   self.nextthink = (time + 0.010);
   self.attack_finished = (time + 0.010);

};

void () player_cgunc7 = [ 103, player_cgunc8 ] {

   self.weaponframe = 52.000;
   self.nextthink = (time + 0.010);

};

void () player_cgunc8 = [ 104, player_cgunc9 ] {

   self.weaponframe = 53.000;
   self.nextthink = (time + 0.010);
   self.bondoflag = self.bondoflag - B_CHAINGUN;

	   sound (self,CHAN_WEAPON,"chaingun/engine3.wav",1.000,ATTN_NORM);

};

void () player_cgunc9 = [ 103, player_cgunc10 ] {

   self.weaponframe = 54.000;
   self.nextthink = (time + 0.010);

};

void () player_cgunc10 = [ 104, player_cgunc11 ] {

   self.weaponframe = 55.000;
   self.nextthink = (time + 0.010);

};

void () player_cgunc11 = [ 103, player_cgunc12 ] {

   self.weaponframe = 56.000;
   self.nextthink = (time + 0.010);

};

void () player_cgunc12 = [ 104, player_cgunc13 ] {

   self.weaponframe = 57.000;
   self.nextthink = (time + 0.010);

};

void () player_cgunc13 = [ 103.000, player_cgunc14 ] {

   self.weaponframe = 58.000;
   self.nextthink = (time + 0.010);

};

void () player_cgunc14 = [ 104, player_cgunc15 ] {

   self.weaponframe = 59.000;
   self.nextthink = (time + 0.010);

};

void () player_cgunc15 = [ 103, player_cgunc16 ] {

   self.weaponframe = 60.000;
   self.nextthink = (time + 0.010);

};

void () player_cgunc16 = [ 104, player_cgunc17 ] {

   self.weaponframe = 61.000;
   self.nextthink = (time + 0.010);

};

void () player_cgunc17 = [ 103, player_cgunc18 ] {

   self.weaponframe = 62.000;
   self.nextthink = (time + 0.010);

};

void () player_cgunc18 = [ 104, player_run ] {

   self.weaponframe = 63.000;
   self.nextthink = (time + 0.010);

};

//chaingun is the reload animation
void () player_chaingun1 = [ 12, player_chaingun2 ] {

   self.weaponframe = 14.000;
   self.nextthink = (time + 0.050);

	   sound (self,CHAN_VOICE,"chaingun/reload.wav",1.000,ATTN_NORM);
   self.attack_finished = (time + 0.500);

};

void () player_chaingun2 = [ 12, player_chaingun3 ] {

   self.weaponframe = 15.000;
   self.nextthink = (time + 0.050);
   //self.weapon4 = 1.000;

};

void () player_chaingun3 = [ 13, player_chaingun4 ] {

   self.weaponframe = 16.000;
   self.nextthink = (time + 0.050);

};

void () player_chaingun4 = [ 13, player_chaingun5 ] {

   self.weaponframe = 17.000;
   self.nextthink = (time + 0.050);

};

void () player_chaingun5 = [ 14, player_chaingun6 ] {

   self.weaponframe = 18.000;
   self.nextthink = (time + 0.050);

};

void () player_chaingun6 = [ 14, player_chaingun7 ] {

   self.weaponframe = 19.000;
   self.nextthink = (time + 0.050);

};

void () player_chaingun7 = [ 15, player_chaingun8 ] {

   self.weaponframe = 20.000;
   self.nextthink = (time + 0.050);

};

void () player_chaingun8 = [ 15, player_chaingun9 ] {

   self.weaponframe = 21.000;
   self.nextthink = (time + 0.050);

};

void () player_chaingun9 = [ 16, player_chaingun10 ] {

   self.weaponframe = 22.000;
   self.nextthink = (time + 0.050);

};

void () player_chaingun10 = [ 16, player_run ] {

   self.weaponframe = 23.000;
   self.nextthink = (time + 0.050);

};

void () player_chaingunb1 = [ 12, player_chaingunb2 ] {

   self.weaponframe = 24.000;
   self.nextthink = (time + 0.050);

	   sound (self,CHAN_WEAPON,"chaingun/reload.wav",1.000,ATTN_NORM);
   self.attack_finished = (time + 0.500);

};

void () player_chaingunb2 = [ 12, player_chaingunb3 ] {

   self.weaponframe = 25.000;
   self.nextthink = (time + 0.050);
   //self.weapon4 = 1.000;

};

void () player_chaingunb3 = [ 13, player_chaingunb4 ] {

   self.weaponframe = 26.000;
   self.nextthink = (time + 0.050);

};

void () player_chaingunb4 = [ 13, player_chaingunb5 ] {

   self.weaponframe = 27.000;
   self.nextthink = (time + 0.050);

};

void () player_chaingunb5 = [ 14, player_chaingunb6 ] {

   self.weaponframe = 28.000;
   self.nextthink = (time + 0.050);

};

void () player_chaingunb6 = [ 14, player_chaingunb7 ] {

   self.weaponframe = 29.000;
   self.nextthink = (time + 0.050);

};

void () player_chaingunb7 = [ 15, player_chaingunb8 ] {

   self.weaponframe = 30.000;
   self.nextthink = (time + 0.050);

};

void () player_chaingunb8 = [ 15, player_chaingunb9 ] {

   self.weaponframe = 31.000;
   self.nextthink = (time + 0.050);

};

void () player_chaingunb9 = [ 16, player_chaingunb10 ] {

   self.weaponframe = 32.000;
   self.nextthink = (time + 0.050);

};

void () player_chaingunb10 = [ 16, player_run ] {

   self.weaponframe = 33.000;
   self.nextthink = (time + 0.050);

};
