void (float damage) spawn_touchblood;
void (float damage) spawnalien_touchblood;
void (vector org, vector vel) SpawnChunk;
/*

void () AxeTouch = {

local float clink;

local float damage;

	if ( ((other == self.owner) && (self.num_bounces == 1)) ) { // if its the owner, and it aint bounced...
		return ; // dont worry about it :)
	}
	else // otherwise
	{
		self.avelocity = '300 300 300'; // air velocity 
		self.movetype = MOVETYPE_BOUNCE; // how it moves (bounces)
		setsize (self,'-1 -2 -3','1 2 3'); // size of entity
		self.nextthink = time + 5; // wait 5 secs...
		self.think = SUB_Remove; // get rid of it
	}
	
	if ( (other.takedamage && (self.velocity != VEC_ORIGIN)) ) { // if it is a hurtable thing...
	
	if ( (self.num_bounces == 1) ) { // if it aint bounced yet
	spawn_touchblood (40); // draw some blood
	SpawnChunk (self.origin,self.velocity); // chuck a chunk
	other.punchangle_x = -20; // angles
	other.axhitme = 1;
	
	if ( (other.health < 10) )

	{ // if hurtable has less than 21 health (changeable)
		damage = 50000; // GIB IT!!!
	}
	else
	
	{ // otherwise
	damage = 50; // do 80 damage (changeable)
	}

	T_Damage (other,self,self.owner,damage);
	} else { // otherwise (back to bounce thing)
	other.punchangle_x = -10;
	spawn_touchblood (25); // spawn some blood
	self.velocity = (self.velocity * -0.5); // change speeds
	other.axhitme = 1;
	if ( (other.health < 21) ) { // if less than 21 health
	damage = 50000; // um...
	} else {
	damage = 20; // otherwise do 20 (changeable)
	}
	T_Damage (other,self,self.owner,20);
	}
	} else { // if it aint hittin a hurtable...
	clink = (random () * 2); // bounce it
	if ( (clink <= 1) ) {
	sound (self,CHAN_WEAPON,"player/axhit2.wav",1,ATTN_NORM); // play sound (precache)
	} else {
	sound (self,CHAN_WEAPON,"weapons/tink1.wav",1,ATTN_NORM); // sound (precache)
	}
	}
	self.num_bounces = (self.num_bounces + 1); // add to the bounces
	if ( (self.num_bounces > 15) ) { // if it gets to 12
	SUB_Remove (); // get it outta here!
	}
};
*/

void() AxeThink =
{
      if(random() <= 0.5)
      	sound (self, CHAN_WEAPON, "player/tornoff2.wav", 1, ATTN_NORM);

      //self.wait = self.wait - 0.1;

      /*
      if ((self.enemy.health <= 10))
		{
   		// Gib them!!
         if (self.enemy.health <= 1)
         T_Damage (self.enemy, self, self.owner, 500);
			remove(self);
         return;
		}
	*/
	
        T_Damage (self.enemy, self, self.owner, 1);
        if (self.enemy.health <= 0)
        	SUB_Remove();
        	
        if (self.enemy.classname == "player")
        		spawn_touchblood(6);
        else
        		spawnalien_touchblood(6);
        
        self.origin = self.enemy.origin + '0 0 8';

        //self.origin_z = self.origin_z + (random() * 5);

        self.nextthink = time + 0.1;
        self.bondo = self.bondo + 1;
        
        if (self.bondo < 20)
        	self.think = AxeThink;
        else
         self.think = SUB_Remove;
};

void() T_AxeTouch =
{
	
	if (other == self.owner)
		return;

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

		if (pointcontents(self.origin) == CONTENT_SKY)
	{
			remove(self);
			return;
	}
	
	if (other.takedamage)
	{
        if (self.enemy.classname == "player")
        		spawn_touchblood(6);
        else
        		spawnalien_touchblood(6);

   T_Damage (other, self, self.owner, 25);
	//sound (self, CHAN_WEAPON, "player/tornoff2.wav", 1, ATTN_NORM);
	self.enemy = other;
	self.origin = other.origin + '0 5 12';
	//Time until The Blender stops killing its victim:
	//self.wait = 1;
	self.nextthink = time;
   self.think = AxeThink;
	self.movetype = MOVETYPE_NOCLIP;
	self.velocity = '0 0 0' ;
   self.avelocity = '0 1000 1000';
   self.bondo = 0;
                
		return;
	}
	else
	{
	   sound (self,CHAN_WEAPON,"player/axhit2.wav",WEAPON_SHOTGUN,ATTN_NORM);
   	self.velocity = VEC_ORIGIN;
	   self.avelocity = VEC_ORIGIN;
   	self.think = SUB_Remove;
	   self.nextthink = time + 5;
   	self.touch = SUB_Null;
	}     

};


void () W_ThrowAxe = {

local entity missile;

	if (random() < 0.3)
		sound (self,CHAN_WEAPON,"weapons/whoosh1.wav",1,ATTN_NORM); 
	else if (random() < 0.6)
		sound (self,CHAN_WEAPON,"weapons/whoosh2.wav",1,ATTN_NORM); 
	else
		sound (self,CHAN_WEAPON,"weapons/whoosh3.wav",1,ATTN_NORM); 
		
self.punchangle_x = CONTENT_SKY;
missile = spawn (); // spawn it
missile.owner = self; // own it
missile.classname = "throwaxe";
missile.movetype = MOVETYPE_FLYMISSILE; // fly movement
missile.solid = SOLID_TRIGGER; // solid entity with a touch function
makevectors (self.v_angle); // shoot it forward the way yer facing
missile.velocity = aim (self,10000);
missile.angles = vectoangles (missile.velocity);
missile.velocity = (missile.velocity * 1000); // speeds etc...

//	if (random() < 0.5)
		missile.touch = T_AxeTouch; // if it hits call the touch func
//	else
//		missile.touch = AxeTouch; // bounce function

missile.nextthink = (time + 10); // if it is flyin fer 10 mins
missile.think = SUB_Remove; // get rid of it :)
setmodel (missile,"progs/throwaxe.mdl"); 
setsize (missile,VEC_ORIGIN,VEC_ORIGIN);
setorigin (missile,((self.origin + (v_forward * 2)) + '0 0 16')); // location of first spawnin
missile.avelocity = '-500 0 0';
missile.num_bounces = 1; // set the bounce level

};


