//------------------------------------------------------------------------------------
// Ninja stars
//------------------------------------------------------------------------------------

void() T_StarTouch =
{
  local float rand;
  local float r, zone;
  if ((other.classname == "player") &&
      (self.velocity == '0 0 0'))
  {
    if (other.ammo_nails >= MAXAMMO_SHURIKEN)
      return;
    other.ammo_nails = other.ammo_nails + 1;
    sound(other, CHAN_ITEM, "weapons/lock4.wav", 0.6, ATTN_NORM);
    sprint(other, "You got the Shuriken\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, SHURIKEN_DAMAGE + (random() * SHURIKEN_DAMAGE_ADDRANDOM), zone, "shuriken", "");
    remove(self);
  }
  else if ((other.solid == SOLID_BSP) && (other.movetype == MOVETYPE_PUSH))
  {
      sound (self, CHAN_AUTO, "weapons/starhit.wav", 1, ATTN_NORM);
      self.velocity = '0 0 0';
      self.movetype = MOVETYPE_NONE;
      self.avelocity = '0 0 0';
  }
  else
    remove(self);
};

void() W_FireStar =
{
  local entity missile;
  local float r;

  self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  if (self.waterlevel > 2) 
    sound(self, CHAN_WEAPON, "misc/water2.wav", 1, ATTN_NORM);
  else 
    sound(self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
//  self.punchangle_x = -4;
  missile = spawn();
  missile.owner = self;
  if (self.waterlevel >= 2)
    missile.movetype = MOVETYPE_BOUNCE;
  else
    missile.movetype = MOVETYPE_FLYMISSILE;
  missile.flags = FL_ITEM;
  missile.solid = SOLID_TRIGGER;
  makevectors(self.v_angle);
  missile.velocity = aim(self, 1000);
  missile.avelocity_y = mrand()*700;
	if(self.randomf)
		r = (time - self.randomf) / SHURIKEN_RANDOMTIME;
	else
		r = 0;
	r = SHURIKEN_INITIALRANDOM + ((SHURIKEN_MAXRANDOM - SHURIKEN_INITIALRANDOM) * r);

  if (self.waterlevel >= 2)
  {
    missile.velocity = missile.velocity * 300;
    missile.avelocity = '200 100 300';
  }
  else
    missile.velocity = missile.velocity * 1300 + crandom() * v_right * r + crandom() * v_up * r;
  missile.angles = vectoangles(missile.velocity);
  missile.touch = T_StarTouch;
  missile.nextthink = time + SHURIKEN_TIME;
  missile.think = SUB_Remove;
  setmodel(missile, "progs/star.mdl");
  setsize(missile, VEC_ORIGIN, VEC_ORIGIN);
  setorigin(missile, self.origin + v_forward * 8 + '0 0 16');
};

