//------------------------------------------------------------------------------------
// Daggers
//------------------------------------------------------------------------------------

void() T_DaggerTouch =
{
  local float rand;
  local float r, zone;
  if ((other.classname == "player") &&
      (self.velocity == '0 0 0'))
  {
    if (other.ammo_cells >= MAXAMMO_DAGGERS)
      return;
    other.ammo_cells = other.ammo_cells + 1;
    sound(other, CHAN_ITEM, "weapons/lock4.wav", 0.6, ATTN_NORM);
    sprint(other, "You got the dagger\n");
    remove(self);
    return;
  }
  if (pointcontents(self.origin) == CONTENT_SKY) 
  {
    remove(self);
    return;
  }
  if (other.takedamage)
  {
    if (other == self.owner)
	return;
    spawn_touchblood(20);
    sound(self, CHAN_WEAPON, "weapons/met2flsh.wav", 1, ATTN_NORM);
    zone = DetermineZone(self, other.origin);
    T_Damage(other, self, self.owner, DAGGER_DAMAGE + (random() * DAGGER_DAMAGE_ADDRANDOM), zone, "dagger", "");
    remove(self);
  }
  else
  {
    sound (self, CHAN_AUTO, "weapons/starhit.wav", 1, ATTN_NORM); ???
    self.velocity = '0 0 0';
    self.movetype = MOVETYPE_NONE;
    self.avelocity = '0 0 0';
  }
};

void(entity p) W_FireDagger =
{
  local entity missile;
  local float r;

  self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  if (p.waterlevel > 2) 
    sound(p, CHAN_WEAPON, "misc/water2.wav", 1, ATTN_NORM);
  else 
    sound(p, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
//  p.punchangle_x = -4;
  missile = spawn();
  missile.owner = p;
  if (p.waterlevel >= 2)
    missile.movetype = MOVETYPE_BOUNCE;
  else
    missile.movetype = MOVETYPE_FLYMISSILE;
  missile.flags = FL_ITEM;
  missile.solid = SOLID_TRIGGER;
  makevectors(p.v_angle);
  missile.velocity = aim(p, 1000);
  missile.avelocity_y = mrand()*700;
  if (p.waterlevel >= 2)
  {
    missile.velocity = missile.velocity * 300;
    missile.avelocity = '200 100 300';
  }
  else
    missile.velocity = missile.velocity * 1300 + crandom() * v_right + crandom() * v_up;
  missile.angles = vectoangles(missile.velocity);
  missile.touch = T_DaggerTouch;
  missile.nextthink = time + DAGGER_TIME;
  missile.think = SUB_Remove;
  setmodel(missile, "progs/dagger.mdl");
  setsize(missile, VEC_ORIGIN, VEC_ORIGIN);
  if(self.count == 3)
    setorigin(missile, self.origin - v_right * 16 + v_forward * 8 + '0 0 16');
  else if(self.count == 2)
    setorigin(missile, self.origin + v_forward * 8 + '0 0 16');
  else if(self.count)
    setorigin(missile, self.origin + v_right * 16 + v_forward * 8 + '0 0 16');
  self.count = self.count - 1;
  self.nextthink = time + DAGGER_DELAY;
  if(self.count <= 0)
	remove(self);
};

void() W_ThrowDaggers =
{
	local entity e;
	e = spawn();
	e.owner = self;
	e.think = W_FireDagger(self);
	e.nextthink = time;
	e.count = 3;
};
