float WP_NAPALMGREN = 64;
float IM_NAPALMGREN = 77;

void() NapalmGrenadeExplode =
{
	local entity fuel;
	local float tmp;
	
	WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
	WriteByte (MSG_BROADCAST, TE_EXPLOSION);
	WriteCoord (MSG_BROADCAST, self.origin_x);
	WriteCoord (MSG_BROADCAST, self.origin_y);
	WriteCoord (MSG_BROADCAST, self.origin_z);

	tmp=0;
	while(tmp<25)
	{
		fuel=spawn();
		fuel.owner=self.owner;
		fuel.movetype=MOVETYPE_FLYMISSILE;
		fuel.solid=SOLID_BBOX;
		fuel.classname="napalm";
		fuel.think=SUB_Null;
		fuel.takedamage=DAMAGE_AIM;
		fuel.health=1;
		fuel.th_die=NapalmDie;
		fuel.velocity_z= -500;
		fuel.velocity_y=100*crandom();
		fuel.velocity_x=100*crandom();
		fuel.avelocity='300 300 300';
		fuel.angles=vectoangles(fuel.velocity);
		fuel.touch=NapalmTouch;
		setmodel(fuel,"progs/spike.mdl");
		setsize(fuel,'0 0 0','0 0 0');
		setorigin(fuel,self.origin);
		tmp=tmp+1;
	}
	BecomeExplosion();
};

void() NapalmGrenadeTouch =
{
	if (pointcontents(self.origin)==CONTENT_SKY)
	{
		remove(self);
		return;
	}
	NapalmGrenadeExplode();
};

void() NapalmPopperExplode =
{
	local entity pop;
	pop=spawn();
	pop.owner=self.owner;
	pop.movetype=MOVETYPE_BOUNCE;
	pop.solid=SOLID_BBOX;
	pop.classname="napalmgrenade";
	pop.velocity='0 0 600';
	pop.angles=vectoangles(pop.velocity);
	pop.touch=NapalmGrenadeTouch;
	pop.think=NapalmGrenadeExplode;
	pop.nextthink=time+1;
	setmodel(pop,"progs/grenade.mdl");
	setsize(pop,'0 0 0','0 0 0');
	setorigin(pop,self.origin);
	BecomeExplosion();
};

void() NapalmPopperTouch =
{
	if (other.takedamage == DAMAGE_AIM)
	{
		NapalmPopperExplode();
		return;
	}
	sound(self,CHAN_WEAPON,"weapons/bounce.wav",1,ATTN_NORM);
	if (self.velocity=='0 0 0')
		self.avelocity='0 0 0';		
};

void() W_FireNapalmGrenade =
{
	local entity missile;
	local float temp;
	
	if (self.currentammo<1)
	{
		self.weapon=W_BestWeapon();
		W_SetCurrentAmmo();
		self.ef=0;
		return;
	}
	self.ammo_rockets=self.ammo_rockets - 1;
	self.ammo_napalm=self.ammo_napalm - 25;
	temp=floor(self.ammo_napalm/25);
	self.currentammo=min(self.ammo_rockets,temp);
	sound(self,CHAN_WEAPON,"weapons/grenade.wav",1,ATTN_NORM);
	self.punchangle_x= -2;
	missile=spawn();
	missile.owner=self;
	missile.movetype=MOVETYPE_BOUNCE;
	missile.solid=SOLID_BBOX;
	missile.classname="napalmpopper";
	makevectors(self.v_angle);
	if (self.v_angle_x)
		missile.velocity=v_forward*600+v_up*200+crandom()*v_right*10+crandom()*v_up*10;
	else
	{
		missile.velocity=aim(self,10000);
		missile.velocity=missile.velocity*600;
		missile.velocity_z=200;
	}
	missile.avelocity='300 300 300';
	missile.angles=vectoangles(missile.velocity);
	missile.touch=NapalmPopperTouch;
	missile.think=NapalmPopperExplode;
	missile.nextthink=time+2.5;
	setmodel(missile,"progs/grenade.mdl");
	setsize(missile,'0 0 0','0 0 0');
	setorigin(missile,self.origin);
};