float() crandom;
void() s_explode1;
void() BecomeExplosion;
void() ShotRockExplode;
void() W_FireShotRock;
void() ShotRockTouch;

float WP_FRAGROCK = 4;
float IM_FRAGROCK = 72;

void() ShotRockExplode =
{
	local entity spike;
	local float tmp=0;
	while (tmp<20) {
		tmp=tmp+1;
		// new entity
		spike=spawn();
		// set owner
		spike.owner=self.owner;
		// moves like a spike
		spike.movetype=MOVETYPE_FLYMISSILE;
		spike.solid=SOLID_BBOX;
		spike.velocity=self.velocity;
		// add spread
		spike.angles=vectoangles(spike.velocity);
		makevectors(spike.angles);
		spike.velocity=spike.velocity+v_right*100*crandom()+v_up*100*crandom();
		spike.angles=vectoangles(spike.velocity);
		spike.touch=ShrapnelTouch;
		spike.classname="shrapnel";
		spike.think=SUB_Remove;
		spike.nextthink=time+6;
		setmodel(spike,"progs/spike.mdl");
		setsize(spike,'0 0 0','0 0 0');
		setorigin(spike,self.origin);
	}
	// tell the net
	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);
	// byebye
	self.solid=SOLID_NOT;
	sound(self,CHAN_WEAPON,"weapons/grenade.wav",1,ATTN_NORM);
	BecomeExplosion();
};
	
void() ShotRockTouch =
{
	if(pointcontents(self.origin)==CONTENT_SKY)
	{
		remove(self);
		return;
	}
	ShotRockExplode();
};

void() W_FireShotRock =
{
	local entity missile;
	self.ammo_rockets=self.ammo_rockets - 1;
	self.ammo_nails=self.ammo_nails - 20;
	self.currentammo=self.currentammo - 1;
	sound(self,CHAN_WEAPON, "weapons/sgun1.wav",1,ATTN_NORM);
	self.punchangle_x= -2;
	missile=spawn();
	missile.owner=self;
	missile.movetype = MOVETYPE_FLYMISSILE;
	missile.solid = SOLID_BBOX;
	makevectors(self.v_angle);
	missile.velocity=aim(self,1000);
	missile.velocity=missile.velocity*1000;
	missile.angles=vectoangles(missile.velocity);
	missile.touch=ShotRockTouch;
	missile.nextthink=time+0.2;
	missile.think=ShotRockExplode;
	setmodel(missile,"progs/missile.mdl");
	setsize(missile,'0 0 0','0 0 0');
	setorigin(missile,self.origin+v_forward*8+'0 0 16');
};
