
/*
 * 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	"@(#)bon.c	1.1 :/usr/key/jojow/X/src/guts/SCCS/s.bon.c 3/19/91 10:14:41 "

/* bon.c - support for bonus's */

#include "server.h"

#define BONTIME		9

place_bonus(tp,nx,ny)
	tank_t *tp;
{
	static int bontime = 0;
	bon_t *bp;

	if( ++bontime < BONTIME )
		return;

	/* if all expended, return */
	if( !(bp = Bfree) ) 
		return;

	bontime = 0;

	Bfree = bp->b_next;

	bp->b_x = nx;
	bp->b_y = ny;

	field[nx][ny] = FBON;
	fpts[nx][ny] = (void *)bp;

	bp->b_next = Bvalid;
	Bvalid = bp;
}


bonblow(tp,bp,nx,ny)
	tank_t *tp;
	bon_t *bp;
	int nx, ny;
{
	bon_t *br;


	/* remove the bonus */
	field[nx][ny] = FSPACE;
	fpts[nx][ny] = NULL;

	if( Bvalid == bp)
		Bvalid = bp->b_next;
	else {
		for( br = Bvalid ; br->b_next != bp ; br = br->b_next );
		br->b_next = bp->b_next;
	}

	bp->b_next = Bfree;
	Bfree = bp;

	/* figure out what the bonus is */

	switch( (int)(random() % 3) ) {
		
		/* raise energy */
		case 0: {
			int energy;


			energy = Tmaxenergy * 3;

			Totenergy -= energy;
			Totenergy += tp->t_energy;
			tp->t_energy = energy;

			break;
		}

		/* raise damage */
		case 1: 
			tp->t_damage = Tdamage * 3;
			break;

		/* destruction */
		case 2: {
			tankdest(tp);
			powdest(tp);
			shelldest();
			heatdest();
			minedest();
			break;
		}
	}
}


checkbons()
{
	static int bpri = 0;

	if( !Bvalid )
		return;

	if( ++bpri < BONUSPRI )
		return;

	bpri = 0;

	Bonfrm = !Bonfrm;
	Servstate |= SSCUDFRC;
}

/* Lint Output
*/
