/*This is basically AsmodeusB's solid corpse code changed a little
bit to be more accomodating to solid gibbed heads
*/

void() HeadPain =
{
 SpawnMeatSpray (self.origin, crandom() * 100 * v_right);
};

void() HeadMove = 
{
 local float dir;

 if(other.takedamage != DAMAGE_AIM)     // not living
   return;

 self.origin_z = self.origin_z + 2;             // lift off of the ground
 self.velocity_x = other.velocity_x;
 self.velocity_y = other.velocity_y;
 // no z or we can push the head into the ground

 self.velocity = self.velocity + '0 0 7';	// add lift
 
 if(self.flags & FL_ONGROUND)
   self.flags = self.flags - FL_ONGROUND;
};

void() HeadDie =
{
     if (damage_attacker.classname == "teledeath")
             sound (self, CHAN_VOICE, "player/teledth1.wav", 1, ATTN_NONE);
     else if (damage_attacker.classname == "teledeath2")
             sound (self, CHAN_VOICE, "player/teledth1.wav", 1, ATTN_NONE);
     else
         sound (self, CHAN_VOICE, "player/udeath.wav", 1, ATTN_NORM);
     ThrowGib ("progs/zom_gib.mdl", self.health);
     ThrowGib ("progs/zom_gib.mdl", self.health);
     ThrowGib ("progs/zom_gib.mdl", self.health);
     remove(self);
};

void() MakeSolidHead =
{
        self.health = 10;
// DAMAGE_AIM so that grenades don't bounce off like they do for DAMAGE_YES
        self.movetype = MOVETYPE_STEP;
	self.takedamage = DAMAGE_AIM;
	self.solid = SOLID_BBOX;
	self.flags = self.flags & (!FL_MONSTER);
        self.touch = HeadMove;
	setsize (self, '-16 -16 0', '16 16 56');
	self.th_stand = SUB_Null;
	self.th_walk = SUB_Null;
	self.th_run = SUB_Null;
        self.th_pain = HeadPain;
	self.th_melee = SUB_Null;
	self.th_missile = SUB_Null;
        self.th_die = HeadDie;
};
