//gas gun
//infect and damage entities

void () GasThink2 =
{

	self.velocity = self.velocity + crandom()*v_right*50 +crandom()*v_up*50;
	
	if (self.wait <= 0)
	{
		self.think = SUB_Remove;
		self.nextthink = time + random()*0.5;
	}
	else
	{
		self.think = GasThink2;
		self.nextthink = time + 0.1;
	}
	self.wait = self.wait - 0.1;

	particle (self.origin,crandom()*v_right*50 + crandom()*v_up*50,85,64);
	particle (self.origin,crandom()*v_right*50 + crandom()*v_up*50,80,96);
	particle (self.origin,crandom()*v_right*50 + crandom()*v_up*50,90,64);
	particle (self.origin,crandom()*v_right*50 + crandom()*v_up*50,60,96);

};


void () GasThink3 =
{

	if (self.wait < 0)
	{
		self.think = SUB_Remove;
		self.nextthink = time + random()*0.5;
	}
	else
	{
		self.cnt = self.cnt*2;
		T_Damage(self.enemy,self,self.owner,self.cnt);
		self.nextthink = time + 0.25;
		self.think = GasThink3;
		self.wait = self.wait - 0.25;
		particle (self.enemy.origin + v_right*crandom()*64 + v_forward*crandom()*64,'0 0 250',85,64);
		particle (self.enemy.origin + v_right*crandom()*64 + v_forward*crandom()*64,'0 0 250',80,96);
		particle (self.enemy.origin + v_right*crandom()*64 + v_forward*crandom()*64,'0 0 250',90,64);
		particle (self.enemy.origin + v_right*crandom()*64 + v_forward*crandom()*64,'0 0 250',60,96);
	}

};

void () GasTouch2 =
{
   local float damg;

   if ( (other == self.owner) ) {

      return ;

   }
   if ( (pointcontents (self.origin) == CONTENT_SKY) ) {

      remove (self);
      return ;

   }
   if ( other.health ) {

		T_Damage (other,self,self.owner,P2DAMAGE); //120
		self.think = GasThink3;
		self.nextthink = time + 0.1;
		self.cnt = P2DAMAGE;
		self.wait = 3;
		self.enemy = other;
		setorigin(self,other.origin);
		self.velocity = VEC_ORIGIN;

   }
   //T_RadiusDamage (self,self.owner,P4DAMAGE,other);

};

void () W_FireGasgun = {

   local entity missile;

	if (self.ammo_nails < 1)
	{
		self.weapon = W_BestWeapon();
		W_SetCurrentAmmo();
		return;
	}

   sound (self,CHAN_WEAPON,"weapons/sgun1.wav",TRUE,ATTN_NORM);
   if (!(self.ringofpower_time)) 
	{
		self.currentammo = self.ammo_nails = (self.ammo_nails - 1);
	}   		
   
   local float n;
   n = 3;
   do {
   missile = spawn ();
   missile.owner = self;
   missile.movetype = MOVETYPE_FLYMISSILE;
   missile.solid = SOLID_BBOX;
   missile.classname = "gas";
   missile.velocity = b_aim(self.origin);
   missile.velocity = (missile.velocity * 800.000);
   makevectors (self.v_angle);
   //added to make rpods fly like drunk missiles
   missile.angles = vectoangles (missile.velocity); //unchanged
   missile.touch = GasTouch2;
   missile.effects = EF_DIMLIGHT;
   missile.nextthink = (time + 0.1);
   missile.think = GasThink2;
   missile.wait = 2;
   setmodel (missile,"");
   setsize (missile,VEC_ORIGIN,VEC_ORIGIN);
   setorigin (missile,((self.origin + (v_forward * 32)) + '0.000 0.000 24.000'));
   n = n - 1;
   } while(self.multiprojectile_time && n > 0);

};
