float () crandom;

void () player_pstorm1;

void () player_pstormf1;

void () player_run;

void () ProtonPrecache = {

   precache_sound ("ps_chrg.wav");
   precache_sound ("ps_fire.wav");
   precache_model ("progs/pstorm.mdl");
   precache_model ("progs/v_pstorm.mdl");

};

void () Proton_Damage = {

   local float n;
   local vector org;
   local entity head;
   local entity selected;

   makevectors (self.owner.v_angle);
   while ( (n < 1000.000) ) {

      n = (n + 70.000);
      selected = world;
      org = (self.owner.origin + (v_forward * n));
      head = findradius (org,85.000);
      traceline (self.owner.origin,org,TRUE,self);
      if ( (trace_fraction >= TRUE) ) {

         while ( head ) {

            if ( (head.health > FALSE) ) {

               traceline (org,head.origin,TRUE,self);
               if ( (trace_fraction >= TRUE) ) {

                  selected = head;
                  if ( ((selected != world) && (selected != self.owner)) ) {

                     T_Damage (selected,self.owner,self.owner,450.000);

                  }

               }

            }
            head = head.chain;

         }

      }

   }

};

void () Storm_Think = {

   local entity stemp;

   if ( ((self.attack_finished < time) || (self.owner.health < TRUE)) ) {

      remove (self);
      stemp = self;
      self = self.owner;
      player_pstormf1 ();
      self.effects = (self.effects - EF_BRIGHTLIGHT);
      remove (stemp);
      return ;

   }
   setorigin (self,self.owner.origin);
   self.nextthink = (time + 0.010);
   self.owner.punchangle_x = (self.owner.punchangle_x * CONTENT_EMPTY);
   makevectors (self.owner.v_angle);
   self.angles = vectoangles (aim (self.owner,1000.000));
   self.angles_z = (random () * 600.000);
   if ( (self.ammo_shells < time) ) {

      Proton_Damage ();
      self.ammo_shells = (time + 0.100);

   }

};

void () Storm_Fire = {

   local entity stemp;


   setorigin (self,self.owner.origin);
   self.angles = self.owner.v_angle;
   self.fixangle = TRUE;
   self.classname = "protonstorm";
   self.ammo_shells = time;
   self.attack_finished = (time + FL_SWIM);
   self.owner.attack_finished = (time + FL_SWIM);
   setmodel (self,"progs/pstorm.mdl");
   self.think = Storm_Think;
   self.nextthink = time;
   stemp = self;
   self = self.owner;
   player_pstorm1 ();
   self.effects = (self.effects | EF_BRIGHTLIGHT);
   self = stemp;
   self.owner.punchangle_x = MOVETYPE_TOSS;

	   self.owner.ammo_cells = (self.owner.ammo_cells - 50.000);
   	self.owner.currentammo = (self.owner.ammo_cells - 50.000);
      sound (self.owner,CHAN_WEAPON,"ps_fire.wav",TRUE,ATTN_NORM);
   

};

void () Storm_ChargeThink = {

   if ( (self.attack_finished < time) ) {

      self.think = Storm_Fire;
      self.nextthink = time;
      return ;

   }
   if ( (self.owner.health < TRUE) ) {

      remove (self);

   }
   makevectors (self.owner.v_angle);
   particle ((((self.owner.origin + '0.000 0.000 22.000') + (v_forward * MOVETYPE_PUSH)) + (v_right * MOVETYPE_TOSS)),((VEC_ORIGIN - (v_forward * FL_SWIM)) + (v_up * TRUE)),40.000,(((MOVETYPE_TOSS + time) - self.attack_finished) * 37.000));
   self.owner.currentammo = (self.owner.currentammo - 0.800);
   self.nextthink = (time + 0.100);

};

void () W_Fire_Storm = {

   local entity storm;

   if ( (self.ammo_cells < 50.0)) {

		sprint(self,"not enough ammo for proton storm\n");
      self.weapon = W_BestWeapon ();
      self.cellguntype = 0;
      W_SetCurrentAmmo ();
      return ;

   }
   storm = spawn ();
   storm.movetype = MOVETYPE_FLY;
   storm.solid = SOLID_TRIGGER;
   storm.owner = self;
   storm.classname = "stormbrewing";
   setorigin (storm,self.origin);
   setsize (storm,VEC_ORIGIN,VEC_ORIGIN);
   storm.think = Storm_ChargeThink;
   storm.attack_finished = (time + MOVETYPE_TOSS);
   storm.nextthink = time;
   self.attack_finished = (time + MOVETYPE_PUSH);
   if ( (self.super_damage_finished > time) ) {

      storm.attack_finished = (time + FL_SWIM);

   }
      sound (self,CHAN_WEAPON,"ps_chrg.wav",TRUE,ATTN_NORM);
   

};

void () player_pstorm1 = [ 112.000, player_pstorm2 ] {

   self.weaponframe = TRUE;

};

void () player_pstorm2 = [ 111.000, player_pstorm3 ] {

   self.weaponframe = FL_SWIM;

};

void () player_pstorm3 = [ 108.000, player_pstorm4 ] {

   self.weaponframe = MOVETYPE_WALK;

};

void () player_pstorm4 = [ 107.000, player_pstorm4 ] {

   self.weaponframe = MOVETYPE_STEP;

};

void () player_pstormf1 = [ 107.000, player_pstormf2 ] {

   self.weaponframe = MOVETYPE_STEP;

};

void () player_pstormf2 = [ 108.000, player_pstormf3 ] {

   self.weaponframe = MOVETYPE_WALK;

};

void () player_pstormf3 = [ 111.000, player_pstormf4 ] {

   self.weaponframe = FL_SWIM;

};

void () player_pstormf4 = [ 112.000, player_run ] {

   self.weaponframe = TRUE;

};
