/*
 * Corpse-related material
 * By AsmodeusB
 * It's a solid corpse which can be gibbed, and moved (by running into it).
 * Also, it falls down if you push it off a cliff. ;)
 */
 

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

void() CorpseMove = 
{
 local float dir;

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

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

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

void() CorpseDie =
{
 local float i;
 local float j;

 sound (self, CHAN_VOICE, "player/udeath.wav", 1, ATTN_NORM);
 // MakeSolidCorpse() sets netname to the head model
 ThrowHead (self.netname, self.health);
 i = 0;
 while(i<3)
 {
  j = random();
  if(j > 0.6)
    ThrowGib ("progs/gib3.mdl", self.health);
  else if(j > 0.3)
    ThrowGib ("progs/gib3.mdl", self.health);
  else
    ThrowGib ("progs/gib3.mdl", self.health);
  i = i + 1;
 }
};


/*
 * This uses entity.netname to hold the head file (for CorpseDie())
 * hack so that we don't have to set anything outside this function.
 */

void(string headmdl) MakeSolidCorpse =
{
// Make a gibbable corpse, change the size so we can jump on it

	self.health = 40;
// DAMAGE_AIM so that grenades don't bounce off like they do for DAMAGE_YES
	self.takedamage = DAMAGE_AIM;
	self.solid = SOLID_BBOX;
	self.movetype = MOVETYPE_STEP;
	self.flags = self.flags & (!FL_MONSTER);
	setsize (self, '-32 -32 -24', '32 32 10');
	self.th_stand = SUB_Null;
	self.th_walk = SUB_Null;
	self.th_run = SUB_Null;
	self.th_pain = CorpsePain;
	self.th_melee = SUB_Null;
	self.th_missile = SUB_Null;
	self.th_die = CorpseDie;
	self.touch = CorpseMove;
	self.netname = headmdl;
};

