//==========================================================================
//  template.txt -- by Patrick Martin           Last updated:  9-11-1997
//--------------------------------------------------------------------------
//  Below is a template of the code I wrote to make the monsters
//  respawn or resurrect back to their former selves.  Such code
//  is placed in the appropriate monster's qc file.  Some of the
//  code calls functions in 'respawn.qc' or 'check.qc'.
//==========================================================================

//-------------------------------------------------------- New Code --------
//  This reconstitutes the monster and sends it back into action.
//--------------------------------------------------------------------------
void()  xxx_restart   =[ $stand1 (or equivalent), xxx_run1  ]
{
        spawn_tfog (self.oldstart);

////////////////////////////////////////////////////////////////////////
// If the monster can fly or swim, now is the place to give back the 
// appropriate flag.  The monster is lifted off the floor a tiny bit
// before the flag is activated.                                    
////////////////////////////////////////////////////////////////////////
        self.flags = self.flags | FL_FLY (or FL_SWIM);

        PM_Reconstitute (<self.mins>, <self.maxs>, <self.max_health>);
        PM_ResetEnemy ();
};

//-------------------------------------------------------- New Code --------
//  The monster's severed head forms into a body, restoring the monster
//  back to full health.
//--------------------------------------------------------------------------
void() xxx_reform =
{
// Reset the size in case it was changed earlier.
        setsize (self, <self.mins>, <self.maxs>);

// If the monster cannot respawn now, try again later.
        if (PM_Occupied(self.oldstart))
        {       setsize (self, '-16 -16 0', '16 16 56');
                PM_Sleep(0);
                self.think = xxx_reform;
                return;
        }

// Respawn the monster.
        spawn_tfog (self.origin + '0 0 41');
        setorigin (self, self.oldstart);
        setmodel (self, "progs/xxx.mdl");
        self.movetype = MOVETYPE_STEP;
        xxx_restart();
};

//-------------------------------------------------------- New Code --------
//  The monster disappears then reappears, alive with full health.
//--------------------------------------------------------------------------
void() xxx_respawn =
{
// Reset the size in case it was changed earlier.
	setsize (self, VEC_HULL2_MIN, VEC_HULL2_MAX);

// If the monster cannot respawn now, try again later.
        if (PM_Occupied(self.oldstart))
        {       PM_Sleep(0);
                self.think = xxx_respawn;
                return;
        }

// Respawn the monster.
        spawn_tfog (self.origin);
        setorigin (self, self.oldstart);
        xxx_restart();
};

//===========================================================================

//--------------------------------------------------------------------------
//  Somewhere in the qc file you will usually find the death animation
//  sequence.  So far, ALL THE ABOVE CODE SHOULD BE PLACED ABOVE and
//  close to this sequence.  You must replace the last function of the
//  sequence with something like the what is shown below.
//--------------------------------------------------------------------------
void() xxx_death1      =[      $death1,        xxx_death2     ] {};
void() xxx_death2      =[      $death2,        xxx_death3     ] {};
        .       .       .       .       .       .       .
        .       .       .       .       .       .       .
        .       .       .       .       .       .       .
void() xxx_death(n-1)  =[      $death(n-1),    xxx_death(n)   ] {};
//-------------------------------------------------------- Code Change -----
void() xxx_death(n)    =[      $death(n),      xxx_death(n+1) ]
{
////////////////////////////////////////////////////////////////////////
// If the condition is met, it will think to 'xxx_respawn'
// instead of 'xxx_death(n+1)' after a delay.
////////////////////////////////////////////////////////////////////////
        if (PM_RespawnMode())
        {       PM_Sleep(0);
                self.think = xxx_respawn;
        }
}
////////////////////////////////////////////////////////////////////////
// This is R.I.P.
////////////////////////////////////////////////////////////////////////
void() xxx_death(n+1)  =[      $death(n),      xxx_death(n+1) ] {};
//--------------------------------------------------------------------------


//---------------------------------------------------------------------------
//  Somewhere below the death sequence (if one existed) is usually
//  a function that checks whether the slain monster should be gibbed.
//  A revival check must be added immediately after the ThrowHead
//  function.  If the 'check for gib' function does not exist
//  (like in fish.qc), then it is HIGHLY RECOMMENDED that you
//  create one.
//---------------------------------------------------------------------------
void() xxx_die =
{
// check for gib
        if (self.health < -35 (or more))
	{
		sound (self, CHAN_VOICE, "player/udeath.wav", 1, ATTN_NORM);
                ThrowHead ("progs/h_xxx.mdl", self.health);
////////////////////////////////////////////////////////////////////////
// NOTE:  If the monster gibbed is a swimmer, then the self.health
//      parameter should be zero.  Thus the line would look like:
//                                                                
//              ThrowHead ("progs/h_xxx.mdl", 0);                   
//                                                                   
//      Otherwise, the 'head' may fly out of the water.  The 'head'   
//      might then respawn on land where it is helpless; and trust me,
//      this does not look good.                                      
////////////////////////////////////////////////////////////////////////
		ThrowGib ("progs/gib1.mdl", self.health);
		ThrowGib ("progs/gib2.mdl", self.health);
		ThrowGib ("progs/gib3.mdl", self.health);
//-------------------------------------------------------- Code Change -----
                if (PM_RespawnMode())
                {       PM_Sleep(0);
                        self.think = xxx_reform;
                }
//--------------------------------------------------------------------------
		return;
	}
	// insert death sounds here
	self.solid = SOLID_NOT;
        xxx_death1();
};

//---------------------------------------------------------------------------
//  END OF FILE.
//---------------------------------------------------------------------------
