float   showedmotd;

/*
===============================================================================

DART STUFF

===============================================================================
*/

void() dartdamage =
{
 if (self.darts > 0)
  if (time >= self.darttime)
   {
    T_Damage(self,self.dart_inflictor,self.dart_attacker,self.darts*2);
    self.darttime = time + 3 ;
   }
};

void() dart_touch =
{
local float rand;
	if (other == self.owner)
		return;

	if (other.solid == SOLID_TRIGGER)
		return;	// trigger field, do nothing

	if (pointcontents(self.origin) == CONTENT_SKY)
	{
		remove(self);
		return;
        }                                     //kb 
	
// hit something that bleeds
	if (other.takedamage)
	{
		spawn_touchblood (9);
		T_Damage (other, self, self.owner, 3);
                if (other.classname == "player")
                 stuffcmd(other,"bf\n");
                other.darts = other.darts + 1 ;
                other.dart_inflictor = self ;
                other.dart_attacker = self.owner;
                if (other.health <= 0)
                 other.deathtype = "poison";
	}
	else
	{
		WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
		
		if (self.classname == "wizspike")
			WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
		else if (self.classname == "knightspike")
			WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
		else
			WriteByte (MSG_BROADCAST, TE_SPIKE);
		WriteCoord (MSG_BROADCAST, self.origin_x);
		WriteCoord (MSG_BROADCAST, self.origin_y);
		WriteCoord (MSG_BROADCAST, self.origin_z);
	}

	remove(self);

};


void(vector org, vector dir) launch_dart =
{
	newmis = spawn ();
	newmis.owner = self;
	newmis.movetype = MOVETYPE_FLYMISSILE;
	newmis.solid = SOLID_BBOX;

	newmis.angles = vectoangles(dir);
                                                 
	newmis.touch = dart_touch;
	newmis.classname = "spike";
	newmis.think = SUB_Remove;
	newmis.nextthink = time + 6;
	setmodel (newmis, "progs/spike.mdl");
	setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);		
	setorigin (newmis, org);

	newmis.velocity = dir * 1000;
/*
                T_Damage (self, self, self, 3);
                self.darts = self.darts + 1 ;
                self.dart_inflictor = self ;
                self.dart_attacker = self;
*/
   //testing. fire a dart, take a dart. kb
};

void(float ox) W_FireDarts =
{
	local vector	dir;
	local entity	old;
	
	makevectors (self.v_angle);

/*
	if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
	{
		W_FireSuperSpikes ();
		return;
	}
*/

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

	self.attack_finished = time + 0.2;
	self.currentammo = self.ammo_nails = self.ammo_nails - 1;
	dir = aim (self, 1000);
        launch_dart (self.origin + '0 0 16' + v_right*ox, dir);

	sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);

	self.punchangle_x = -2;
};

//============================================================================

$frame nailatt1 nailatt2

void()  player_dart1 =  [$nailatt1, player_dart2        ] {self.weaponframe=1;
self.effects = self.effects | EF_MUZZLEFLASH;};
void()  player_dart2 =  [$nailatt2, player_run        ] {self.weaponframe=2;};

//*************************************************************************

void() dartmsg =
{
 if (showedmotd != 666)
  {
   sprint(self,"This server has the following modifications : \n");
   sprint(self,"Poison Dart Gun v0.6. Hit 4 with the nailgun selected, or bind a key to \"impulse 12\" to select.\n");
   sprint(self," Mail kevin_bowen@juno.com for dartgun bugs/questions/suggestions.\n");
   showedmotd = 666 ;
  }
};
