
/*
 * Copyright (c) 1991    Jon Wesener 
 * Gaming Software
 *
 * Permission to use, copy, modify, and distribute this
 * software and its documentation for any purpose and without
 * fee is hereby granted, provided that the above copyright
 * notice appear in all copies and that both that copyright
 * notice and this permission notice appear in supporting
 * documentation.  No representations are made about the
 * suitability of this software for any purpose.  It is
 * provided "as is" without express or implied warranty.
 *
 */

#ident	"@(#)expl.c	1.5 :/usr/key/jojow/X/src/guts/SCCS/s.expl.c 3/19/91 10:15:47 "

/* expl.c - routines for handling explosions */

#include "server.h"

#define EBIG	'b'
#define ESMALL	's'
#define ESMALLSTART	4
#define EXPLDELAY	30

explode(tp,ktp,dmg,x,y)
	tank_t *tp;
	tank_t *ktp;
	int		dmg;
{
	expl_t *ep;
	int		esize = ESMALL;

	
	/* see if we're blowing up a tank */
	if( tp ) {
		tp->t_damage -= dmg;

		if( tp->t_damage < 0 ) {
			Totenergy += tp->t_energy;
			esize = EBIG;
			tp->t_dead++;
			tank_reset(tp,EXPLDELAY);
			field[tp->t_x][tp->t_y] = FSPACE;
			fpts[tp->t_x][tp->t_y] = NULL;
			place_bonus(tp,x,y);
			place_tank(tp);
			if( ktp )
				ktp->t_kills++;
		}
	}

	/* if we're out of explosions, just continue */
	if( !Efree )
		return;

	ep = Efree;
	Efree = ep->e_next;

	ep->e_x = x;
	ep->e_y = y;
	ep->e_frm = (esize == ESMALL) ? ESMALLSTART : 0;
	ep->e_size = esize;
	ep->e_pri = EXPLPRI;

	ep->e_next = Evalid;
	Evalid = ep;
}


checkexpls()
{
	expl_t *ep, *er, *en;


	/* walk down the list */
	for( ep = Evalid ; ep ; ep = er ) {
		
		er = ep->e_next;

		if( ++(ep->e_pri) < EXPLPRI )
			continue;

		ep->e_pri = 0;


		Servstate |= SSCUDFRC;

		if( ++(ep->e_frm) < EXPCNT ) 
			continue;

		/* remove the explosion */
		if( Evalid == ep )
			Evalid = ep->e_next;
		else {
			for( en = Evalid ; en->e_next != ep ; en = en->e_next );
			en->e_next = ep->e_next;
		}
		
		/* add to free list */
		ep->e_next = Efree;
		Efree = ep;
	}
}

/* Lint Output
*/
