Home | History | Annotate | Line # | Download | only in huntd
shots.c revision 1.2
      1  1.2  lukem /*	$NetBSD: shots.c,v 1.2 1997/10/10 16:33:54 lukem Exp $	*/
      2  1.1    mrg /*
      3  1.1    mrg  *  Hunt
      4  1.1    mrg  *  Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold
      5  1.1    mrg  *  San Francisco, California
      6  1.1    mrg  */
      7  1.1    mrg 
      8  1.2  lukem #include <sys/cdefs.h>
      9  1.2  lukem #ifndef lint
     10  1.2  lukem __RCSID("$NetBSD: shots.c,v 1.2 1997/10/10 16:33:54 lukem Exp $");
     11  1.2  lukem #endif /* not lint */
     12  1.2  lukem 
     13  1.2  lukem # include	<signal.h>
     14  1.2  lukem # include	<stdlib.h>
     15  1.1    mrg # include	"hunt.h"
     16  1.1    mrg 
     17  1.1    mrg # define	PLUS_DELTA(x, max)	if (x < max) x++; else x--
     18  1.1    mrg # define	MINUS_DELTA(x, min)	if (x > min) x--; else x++
     19  1.1    mrg 
     20  1.2  lukem static	void	chkshot __P((BULLET *, BULLET *));
     21  1.2  lukem static	void	chkslime __P((BULLET *, BULLET *));
     22  1.2  lukem static	void	explshot __P((BULLET *, int, int));
     23  1.2  lukem static	void	find_under __P((BULLET *, BULLET *));
     24  1.2  lukem static	int	iswall __P((int, int));
     25  1.2  lukem static	void	mark_boot __P((BULLET *));
     26  1.2  lukem static	void	mark_player __P((BULLET *));
     27  1.2  lukem #ifdef DRONE
     28  1.2  lukem static	void	move_drone __P((BULLET *));
     29  1.2  lukem #endif
     30  1.2  lukem static	void	move_flyer __P((PLAYER *));
     31  1.2  lukem static	int	move_normal_shot __P((BULLET *));
     32  1.2  lukem static	void	move_slime __P((BULLET *, int, BULLET *));
     33  1.2  lukem static	void	save_bullet __P((BULLET *));
     34  1.2  lukem static	void	zapshot __P((BULLET *, BULLET *));
     35  1.2  lukem 
     36  1.1    mrg /*
     37  1.1    mrg  * moveshots:
     38  1.1    mrg  *	Move the shots already in the air, taking explosions into account
     39  1.1    mrg  */
     40  1.2  lukem void
     41  1.1    mrg moveshots()
     42  1.1    mrg {
     43  1.2  lukem 	BULLET	*bp, *next;
     44  1.2  lukem 	PLAYER	*pp;
     45  1.2  lukem 	int	x, y;
     46  1.2  lukem 	BULLET	*blist;
     47  1.1    mrg 
     48  1.1    mrg 	rollexpl();
     49  1.1    mrg 	if (Bullets == NULL)
     50  1.1    mrg 		goto ret;
     51  1.1    mrg 
     52  1.1    mrg 	/*
     53  1.1    mrg 	 * First we move through the bullet list BULSPD times, looking
     54  1.1    mrg 	 * for things we may have run into.  If we do run into
     55  1.1    mrg 	 * something, we set up the explosion and disappear, checking
     56  1.1    mrg 	 * for damage to any player who got in the way.
     57  1.1    mrg 	 */
     58  1.1    mrg 
     59  1.1    mrg 	blist = Bullets;
     60  1.1    mrg 	Bullets = NULL;
     61  1.1    mrg 	for (bp = blist; bp != NULL; bp = next) {
     62  1.1    mrg 		next = bp->b_next;
     63  1.1    mrg 		x = bp->b_x;
     64  1.1    mrg 		y = bp->b_y;
     65  1.1    mrg 		Maze[y][x] = bp->b_over;
     66  1.1    mrg 		for (pp = Player; pp < End_player; pp++)
     67  1.1    mrg 			check(pp, y, x);
     68  1.1    mrg # ifdef MONITOR
     69  1.1    mrg 		for (pp = Monitor; pp < End_monitor; pp++)
     70  1.1    mrg 			check(pp, y, x);
     71  1.1    mrg # endif
     72  1.1    mrg 
     73  1.1    mrg 		switch (bp->b_type) {
     74  1.1    mrg 		  case SHOT:
     75  1.1    mrg 		  case GRENADE:
     76  1.1    mrg 		  case SATCHEL:
     77  1.1    mrg 		  case BOMB:
     78  1.1    mrg 			if (move_normal_shot(bp)) {
     79  1.1    mrg 				bp->b_next = Bullets;
     80  1.1    mrg 				Bullets = bp;
     81  1.1    mrg 			}
     82  1.1    mrg 			break;
     83  1.1    mrg # ifdef OOZE
     84  1.1    mrg 		  case SLIME:
     85  1.1    mrg 			if (bp->b_expl || move_normal_shot(bp)) {
     86  1.1    mrg 				bp->b_next = Bullets;
     87  1.1    mrg 				Bullets = bp;
     88  1.1    mrg 			}
     89  1.1    mrg 			break;
     90  1.1    mrg # endif
     91  1.1    mrg # ifdef DRONE
     92  1.1    mrg 		  case DSHOT:
     93  1.1    mrg 			if (move_drone(bp)) {
     94  1.1    mrg 				bp->b_next = Bullets;
     95  1.1    mrg 				Bullets = bp;
     96  1.1    mrg 			}
     97  1.1    mrg 			break;
     98  1.1    mrg # endif
     99  1.1    mrg 		  default:
    100  1.1    mrg 			bp->b_next = Bullets;
    101  1.1    mrg 			Bullets = bp;
    102  1.1    mrg 			break;
    103  1.1    mrg 		}
    104  1.1    mrg 	}
    105  1.1    mrg 
    106  1.1    mrg 	blist = Bullets;
    107  1.1    mrg 	Bullets = NULL;
    108  1.1    mrg 	for (bp = blist; bp != NULL; bp = next) {
    109  1.1    mrg 		next = bp->b_next;
    110  1.1    mrg 		if (!bp->b_expl) {
    111  1.1    mrg 			save_bullet(bp);
    112  1.1    mrg # ifdef MONITOR
    113  1.1    mrg 			for (pp = Monitor; pp < End_monitor; pp++)
    114  1.1    mrg 				check(pp, bp->b_y, bp->b_x);
    115  1.1    mrg # endif
    116  1.1    mrg # ifdef DRONE
    117  1.1    mrg 			if (bp->b_type == DSHOT)
    118  1.1    mrg 				for (pp = Player; pp < End_player; pp++)
    119  1.1    mrg 					if (pp->p_scan >= 0)
    120  1.1    mrg 						check(pp, bp->b_y, bp->b_x);
    121  1.1    mrg # endif
    122  1.1    mrg 			continue;
    123  1.1    mrg 		}
    124  1.1    mrg 
    125  1.1    mrg 		chkshot(bp, next);
    126  1.1    mrg 		free((char *) bp);
    127  1.1    mrg 	}
    128  1.1    mrg 
    129  1.1    mrg 	for (pp = Player; pp < End_player; pp++)
    130  1.1    mrg 		Maze[pp->p_y][pp->p_x] = pp->p_face;
    131  1.1    mrg 
    132  1.1    mrg ret:
    133  1.1    mrg # ifdef BOOTS
    134  1.1    mrg 	for (pp = Boot; pp < &Boot[NBOOTS]; pp++)
    135  1.1    mrg 		if (pp->p_flying >= 0)
    136  1.1    mrg 			move_flyer(pp);
    137  1.1    mrg # endif
    138  1.1    mrg 	for (pp = Player; pp < End_player; pp++) {
    139  1.1    mrg # ifdef FLY
    140  1.1    mrg 		if (pp->p_flying >= 0)
    141  1.1    mrg 			move_flyer(pp);
    142  1.1    mrg # endif
    143  1.1    mrg 		sendcom(pp, REFRESH);	/* Flush out the explosions */
    144  1.1    mrg 		look(pp);
    145  1.1    mrg 		sendcom(pp, REFRESH);
    146  1.1    mrg 	}
    147  1.1    mrg # ifdef MONITOR
    148  1.1    mrg 	for (pp = Monitor; pp < End_monitor; pp++)
    149  1.1    mrg 		sendcom(pp, REFRESH);
    150  1.1    mrg # endif
    151  1.1    mrg 
    152  1.1    mrg 	return;
    153  1.1    mrg }
    154  1.1    mrg 
    155  1.1    mrg /*
    156  1.1    mrg  * move_normal_shot:
    157  1.1    mrg  *	Move a normal shot along its trajectory
    158  1.1    mrg  */
    159  1.2  lukem static int
    160  1.1    mrg move_normal_shot(bp)
    161  1.2  lukem 	BULLET	*bp;
    162  1.1    mrg {
    163  1.2  lukem 	int	i, x, y;
    164  1.2  lukem 	PLAYER	*pp;
    165  1.1    mrg 
    166  1.1    mrg 	for (i = 0; i < BULSPD; i++) {
    167  1.1    mrg 		if (bp->b_expl)
    168  1.1    mrg 			break;
    169  1.1    mrg 
    170  1.1    mrg 		x = bp->b_x;
    171  1.1    mrg 		y = bp->b_y;
    172  1.1    mrg 
    173  1.1    mrg 		switch (bp->b_face) {
    174  1.1    mrg 		  case LEFTS:
    175  1.1    mrg 			x--;
    176  1.1    mrg 			break;
    177  1.1    mrg 		  case RIGHT:
    178  1.1    mrg 			x++;
    179  1.1    mrg 			break;
    180  1.1    mrg 		  case ABOVE:
    181  1.1    mrg 			y--;
    182  1.1    mrg 			break;
    183  1.1    mrg 		  case BELOW:
    184  1.1    mrg 			y++;
    185  1.1    mrg 			break;
    186  1.1    mrg 		}
    187  1.1    mrg 
    188  1.1    mrg 		switch (Maze[y][x]) {
    189  1.1    mrg 		  case SHOT:
    190  1.1    mrg 			if (rand_num(100) < 5) {
    191  1.1    mrg 				zapshot(Bullets, bp);
    192  1.1    mrg 				zapshot(bp->b_next, bp);
    193  1.1    mrg 			}
    194  1.1    mrg 			break;
    195  1.1    mrg 		  case GRENADE:
    196  1.1    mrg 			if (rand_num(100) < 10) {
    197  1.1    mrg 				zapshot(Bullets, bp);
    198  1.1    mrg 				zapshot(bp->b_next, bp);
    199  1.1    mrg 			}
    200  1.1    mrg 			break;
    201  1.1    mrg # ifdef	REFLECT
    202  1.1    mrg 		  case WALL4:	/* reflecting walls */
    203  1.1    mrg 			switch (bp->b_face) {
    204  1.1    mrg 			  case LEFTS:
    205  1.1    mrg 				bp->b_face = BELOW;
    206  1.1    mrg 				break;
    207  1.1    mrg 			  case RIGHT:
    208  1.1    mrg 				bp->b_face = ABOVE;
    209  1.1    mrg 				break;
    210  1.1    mrg 			  case ABOVE:
    211  1.1    mrg 				bp->b_face = RIGHT;
    212  1.1    mrg 				break;
    213  1.1    mrg 			  case BELOW:
    214  1.1    mrg 				bp->b_face = LEFTS;
    215  1.1    mrg 				break;
    216  1.1    mrg 			}
    217  1.1    mrg 			Maze[y][x] = WALL5;
    218  1.1    mrg # ifdef MONITOR
    219  1.1    mrg 			for (pp = Monitor; pp < End_monitor; pp++)
    220  1.1    mrg 				check(pp, y, x);
    221  1.1    mrg # endif
    222  1.1    mrg 			break;
    223  1.1    mrg 		  case WALL5:
    224  1.1    mrg 			switch (bp->b_face) {
    225  1.1    mrg 			  case LEFTS:
    226  1.1    mrg 				bp->b_face = ABOVE;
    227  1.1    mrg 				break;
    228  1.1    mrg 			  case RIGHT:
    229  1.1    mrg 				bp->b_face = BELOW;
    230  1.1    mrg 				break;
    231  1.1    mrg 			  case ABOVE:
    232  1.1    mrg 				bp->b_face = LEFTS;
    233  1.1    mrg 				break;
    234  1.1    mrg 			  case BELOW:
    235  1.1    mrg 				bp->b_face = RIGHT;
    236  1.1    mrg 				break;
    237  1.1    mrg 			}
    238  1.1    mrg 			Maze[y][x] = WALL4;
    239  1.1    mrg # ifdef MONITOR
    240  1.1    mrg 			for (pp = Monitor; pp < End_monitor; pp++)
    241  1.1    mrg 				check(pp, y, x);
    242  1.1    mrg # endif
    243  1.1    mrg 			break;
    244  1.1    mrg # endif
    245  1.1    mrg # ifdef RANDOM
    246  1.1    mrg 		  case DOOR:
    247  1.1    mrg 			switch (rand_num(4)) {
    248  1.1    mrg 			  case 0:
    249  1.1    mrg 				bp->b_face = ABOVE;
    250  1.1    mrg 				break;
    251  1.1    mrg 			  case 1:
    252  1.1    mrg 				bp->b_face = BELOW;
    253  1.1    mrg 				break;
    254  1.1    mrg 			  case 2:
    255  1.1    mrg 				bp->b_face = LEFTS;
    256  1.1    mrg 				break;
    257  1.1    mrg 			  case 3:
    258  1.1    mrg 				bp->b_face = RIGHT;
    259  1.1    mrg 				break;
    260  1.1    mrg 			}
    261  1.1    mrg 			break;
    262  1.1    mrg # endif
    263  1.1    mrg # ifdef FLY
    264  1.1    mrg 		  case FLYER:
    265  1.1    mrg 			pp = play_at(y, x);
    266  1.1    mrg 			message(pp, "Zing!");
    267  1.1    mrg 			break;
    268  1.1    mrg # endif
    269  1.1    mrg 		  case LEFTS:
    270  1.1    mrg 		  case RIGHT:
    271  1.1    mrg 		  case BELOW:
    272  1.1    mrg 		  case ABOVE:
    273  1.1    mrg 			/*
    274  1.1    mrg 			 * give the person a chance to catch a
    275  1.1    mrg 			 * grenade if s/he is facing it
    276  1.1    mrg 			 */
    277  1.1    mrg 			pp = play_at(y, x);
    278  1.1    mrg 			pp->p_ident->i_shot += bp->b_charge;
    279  1.1    mrg 			if (opposite(bp->b_face, Maze[y][x])) {
    280  1.1    mrg 			    if (rand_num(100) < 10) {
    281  1.1    mrg 				if (bp->b_owner != NULL)
    282  1.1    mrg 					message(bp->b_owner,
    283  1.1    mrg 					    "Your charge was absorbed!");
    284  1.1    mrg 				if (bp->b_score != NULL)
    285  1.1    mrg 					bp->b_score->i_robbed += bp->b_charge;
    286  1.1    mrg 				pp->p_ammo += bp->b_charge;
    287  1.1    mrg 				if (pp->p_damage + bp->b_size * MINDAM
    288  1.1    mrg 				    > pp->p_damcap)
    289  1.1    mrg 					pp->p_ident->i_saved++;
    290  1.1    mrg 				message(pp, "Absorbed charge (good shield!)");
    291  1.1    mrg 				pp->p_ident->i_absorbed += bp->b_charge;
    292  1.1    mrg 				free((char *) bp);
    293  1.1    mrg 				(void) sprintf(Buf, "%3d", pp->p_ammo);
    294  1.1    mrg 				cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
    295  1.1    mrg 				outstr(pp, Buf, 3);
    296  1.1    mrg 				return FALSE;
    297  1.1    mrg 			    }
    298  1.1    mrg 			    pp->p_ident->i_faced += bp->b_charge;
    299  1.1    mrg 			}
    300  1.1    mrg 			/*
    301  1.1    mrg 			 * Small chance that the bullet just misses the
    302  1.1    mrg 			 * person.  If so, the bullet just goes on its
    303  1.1    mrg 			 * merry way without exploding.
    304  1.1    mrg 			 */
    305  1.1    mrg 			if (rand_num(100) < 5) {
    306  1.1    mrg 				pp->p_ident->i_ducked += bp->b_charge;
    307  1.1    mrg 				if (pp->p_damage + bp->b_size * MINDAM
    308  1.1    mrg 				    > pp->p_damcap)
    309  1.1    mrg 					pp->p_ident->i_saved++;
    310  1.1    mrg 				if (bp->b_score != NULL)
    311  1.1    mrg 					bp->b_score->i_missed += bp->b_charge;
    312  1.1    mrg 				message(pp, "Zing!");
    313  1.1    mrg 				if (bp->b_owner == NULL)
    314  1.1    mrg 					break;
    315  1.1    mrg 				message(bp->b_owner,
    316  1.1    mrg 					((bp->b_score->i_missed & 0x7) == 0x7) ?
    317  1.1    mrg 					"My!  What a bad shot you are!" :
    318  1.1    mrg 					"Missed him");
    319  1.1    mrg 				break;
    320  1.1    mrg 			}
    321  1.1    mrg 			/*
    322  1.1    mrg 			 * The shot hit that sucker!  Blow it up.
    323  1.1    mrg 			 */
    324  1.1    mrg 			/* FALLTHROUGH */
    325  1.1    mrg # ifndef RANDOM
    326  1.1    mrg 		  case DOOR:
    327  1.1    mrg # endif
    328  1.1    mrg 		  case WALL1:
    329  1.1    mrg 		  case WALL2:
    330  1.1    mrg 		  case WALL3:
    331  1.1    mrg 			bp->b_expl = TRUE;
    332  1.1    mrg 			break;
    333  1.1    mrg 		}
    334  1.1    mrg 
    335  1.1    mrg 		bp->b_x = x;
    336  1.1    mrg 		bp->b_y = y;
    337  1.1    mrg 	}
    338  1.1    mrg 	return TRUE;
    339  1.1    mrg }
    340  1.1    mrg 
    341  1.1    mrg # ifdef	DRONE
    342  1.1    mrg /*
    343  1.1    mrg  * move_drone:
    344  1.1    mrg  *	Move the drone to the next square
    345  1.1    mrg  */
    346  1.2  lukem static void
    347  1.1    mrg move_drone(bp)
    348  1.2  lukem 	BULLET	*bp;
    349  1.1    mrg {
    350  1.2  lukem 	int	mask, count;
    351  1.2  lukem 	int	n, dir;
    352  1.2  lukem 	PLAYER	*pp;
    353  1.1    mrg 
    354  1.1    mrg 	/*
    355  1.1    mrg 	 * See if we can give someone a blast
    356  1.1    mrg 	 */
    357  1.1    mrg 	if (isplayer(Maze[bp->b_y][bp->b_x - 1])) {
    358  1.1    mrg 		dir = WEST;
    359  1.1    mrg 		goto drone_move;
    360  1.1    mrg 	}
    361  1.1    mrg 	if (isplayer(Maze[bp->b_y - 1][bp->b_x])) {
    362  1.1    mrg 		dir = NORTH;
    363  1.1    mrg 		goto drone_move;
    364  1.1    mrg 	}
    365  1.1    mrg 	if (isplayer(Maze[bp->b_y + 1][bp->b_x])) {
    366  1.1    mrg 		dir = SOUTH;
    367  1.1    mrg 		goto drone_move;
    368  1.1    mrg 	}
    369  1.1    mrg 	if (isplayer(Maze[bp->b_y][bp->b_x + 1])) {
    370  1.1    mrg 		dir = EAST;
    371  1.1    mrg 		goto drone_move;
    372  1.1    mrg 	}
    373  1.1    mrg 
    374  1.1    mrg 	/*
    375  1.1    mrg 	 * Find out what directions are clear
    376  1.1    mrg 	 */
    377  1.1    mrg 	mask = count = 0;
    378  1.1    mrg 	if (!iswall(bp->b_y, bp->b_x - 1))
    379  1.1    mrg 		mask |= WEST, count++;
    380  1.1    mrg 	if (!iswall(bp->b_y - 1, bp->b_x))
    381  1.1    mrg 		mask |= NORTH, count++;
    382  1.1    mrg 	if (!iswall(bp->b_y + 1, bp->b_x))
    383  1.1    mrg 		mask |= SOUTH, count++;
    384  1.1    mrg 	if (!iswall(bp->b_y, bp->b_x + 1))
    385  1.1    mrg 		mask |= EAST, count++;
    386  1.1    mrg 
    387  1.1    mrg 	/*
    388  1.1    mrg 	 * All blocked up, just you wait
    389  1.1    mrg 	 */
    390  1.1    mrg 	if (count == 0)
    391  1.1    mrg 		return TRUE;
    392  1.1    mrg 
    393  1.1    mrg 	/*
    394  1.1    mrg 	 * Only one way to go.
    395  1.1    mrg 	 */
    396  1.1    mrg 	if (count == 1) {
    397  1.1    mrg 		dir = mask;
    398  1.1    mrg 		goto drone_move;
    399  1.1    mrg 	}
    400  1.1    mrg 
    401  1.1    mrg 	/*
    402  1.1    mrg 	 * Get rid of the direction that we came from
    403  1.1    mrg 	 */
    404  1.1    mrg 	switch (bp->b_face) {
    405  1.1    mrg 	  case LEFTS:
    406  1.1    mrg 		if (mask & EAST)
    407  1.1    mrg 			mask &= ~EAST, count--;
    408  1.1    mrg 		break;
    409  1.1    mrg 	  case RIGHT:
    410  1.1    mrg 		if (mask & WEST)
    411  1.1    mrg 			mask &= ~WEST, count--;
    412  1.1    mrg 		break;
    413  1.1    mrg 	  case ABOVE:
    414  1.1    mrg 		if (mask & SOUTH)
    415  1.1    mrg 			mask &= ~SOUTH, count--;
    416  1.1    mrg 		break;
    417  1.1    mrg 	  case BELOW:
    418  1.1    mrg 		if (mask & NORTH)
    419  1.1    mrg 			mask &= ~NORTH, count--;
    420  1.1    mrg 		break;
    421  1.1    mrg 	}
    422  1.1    mrg 
    423  1.1    mrg 	/*
    424  1.1    mrg 	 * Pick one of the remaining directions
    425  1.1    mrg 	 */
    426  1.1    mrg 	n = rand_num(count);
    427  1.1    mrg 	if (n >= 0 && mask & NORTH)
    428  1.1    mrg 		dir = NORTH, n--;
    429  1.1    mrg 	if (n >= 0 && mask & SOUTH)
    430  1.1    mrg 		dir = SOUTH, n--;
    431  1.1    mrg 	if (n >= 0 && mask & EAST)
    432  1.1    mrg 		dir = EAST, n--;
    433  1.1    mrg 	if (n >= 0 && mask & WEST)
    434  1.1    mrg 		dir = WEST, n--;
    435  1.1    mrg 
    436  1.1    mrg 	/*
    437  1.1    mrg 	 * Now that we know the direction of movement,
    438  1.1    mrg 	 * just update the position of the drone
    439  1.1    mrg 	 */
    440  1.1    mrg drone_move:
    441  1.1    mrg 	switch (dir) {
    442  1.1    mrg 	  case WEST:
    443  1.1    mrg 		bp->b_x--;
    444  1.1    mrg 		bp->b_face = LEFTS;
    445  1.1    mrg 		break;
    446  1.1    mrg 	  case EAST:
    447  1.1    mrg 		bp->b_x++;
    448  1.1    mrg 		bp->b_face = RIGHT;
    449  1.1    mrg 		break;
    450  1.1    mrg 	  case NORTH:
    451  1.1    mrg 		bp->b_y--;
    452  1.1    mrg 		bp->b_face = ABOVE;
    453  1.1    mrg 		break;
    454  1.1    mrg 	  case SOUTH:
    455  1.1    mrg 		bp->b_y++;
    456  1.1    mrg 		bp->b_face = BELOW;
    457  1.1    mrg 		break;
    458  1.1    mrg 	}
    459  1.1    mrg 	switch (Maze[bp->b_y][bp->b_x]) {
    460  1.1    mrg 	  case LEFTS:
    461  1.1    mrg 	  case RIGHT:
    462  1.1    mrg 	  case BELOW:
    463  1.1    mrg 	  case ABOVE:
    464  1.1    mrg 		/*
    465  1.1    mrg 		 * give the person a chance to catch a
    466  1.1    mrg 		 * drone if s/he is facing it
    467  1.1    mrg 		 */
    468  1.1    mrg 		if (rand_num(100) < 1 &&
    469  1.1    mrg 		opposite(bp->b_face, Maze[bp->b_y][bp->b_x])) {
    470  1.1    mrg 			pp = play_at(bp->b_y, bp->b_x);
    471  1.1    mrg 			pp->p_ammo += bp->b_charge;
    472  1.1    mrg 			message(pp, "**** Absorbed drone ****");
    473  1.1    mrg 			free((char *) bp);
    474  1.1    mrg 			(void) sprintf(Buf, "%3d", pp->p_ammo);
    475  1.1    mrg 			cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
    476  1.1    mrg 			outstr(pp, Buf, 3);
    477  1.1    mrg 			return FALSE;
    478  1.1    mrg 		}
    479  1.1    mrg 		bp->b_expl = TRUE;
    480  1.1    mrg 		break;
    481  1.1    mrg 	}
    482  1.1    mrg 	return TRUE;
    483  1.1    mrg }
    484  1.1    mrg # endif
    485  1.1    mrg 
    486  1.1    mrg /*
    487  1.1    mrg  * save_bullet:
    488  1.1    mrg  *	Put this bullet back onto the bullet list
    489  1.1    mrg  */
    490  1.2  lukem static void
    491  1.1    mrg save_bullet(bp)
    492  1.2  lukem 	BULLET	*bp;
    493  1.1    mrg {
    494  1.1    mrg 	bp->b_over = Maze[bp->b_y][bp->b_x];
    495  1.1    mrg 	switch (bp->b_over) {
    496  1.1    mrg 	  case SHOT:
    497  1.1    mrg 	  case GRENADE:
    498  1.1    mrg 	  case SATCHEL:
    499  1.1    mrg 	  case BOMB:
    500  1.1    mrg # ifdef OOZE
    501  1.1    mrg 	  case SLIME:
    502  1.1    mrg # ifdef VOLCANO
    503  1.1    mrg 	  case LAVA:
    504  1.1    mrg # endif
    505  1.1    mrg # endif
    506  1.1    mrg # ifdef DRONE
    507  1.1    mrg 	  case DSHOT:
    508  1.1    mrg # endif
    509  1.1    mrg 		find_under(Bullets, bp);
    510  1.1    mrg 		break;
    511  1.1    mrg 	}
    512  1.1    mrg 
    513  1.1    mrg 	switch (bp->b_over) {
    514  1.1    mrg 	  case LEFTS:
    515  1.1    mrg 	  case RIGHT:
    516  1.1    mrg 	  case ABOVE:
    517  1.1    mrg 	  case BELOW:
    518  1.1    mrg # ifdef FLY
    519  1.1    mrg 	  case FLYER:
    520  1.1    mrg # endif
    521  1.1    mrg 		mark_player(bp);
    522  1.1    mrg 		break;
    523  1.1    mrg # ifdef BOOTS
    524  1.1    mrg 	  case BOOT:
    525  1.1    mrg 	  case BOOT_PAIR:
    526  1.1    mrg 		mark_boot(bp);
    527  1.1    mrg # endif
    528  1.1    mrg 
    529  1.1    mrg 	  default:
    530  1.1    mrg 		Maze[bp->b_y][bp->b_x] = bp->b_type;
    531  1.1    mrg 		break;
    532  1.1    mrg 	}
    533  1.1    mrg 
    534  1.1    mrg 	bp->b_next = Bullets;
    535  1.1    mrg 	Bullets = bp;
    536  1.1    mrg }
    537  1.1    mrg 
    538  1.1    mrg /*
    539  1.1    mrg  * move_flyer:
    540  1.1    mrg  *	Update the position of a player in flight
    541  1.1    mrg  */
    542  1.2  lukem static void
    543  1.1    mrg move_flyer(pp)
    544  1.2  lukem 	PLAYER	*pp;
    545  1.1    mrg {
    546  1.2  lukem 	int	x, y;
    547  1.1    mrg 
    548  1.1    mrg 	if (pp->p_undershot) {
    549  1.1    mrg 		fixshots(pp->p_y, pp->p_x, pp->p_over);
    550  1.1    mrg 		pp->p_undershot = FALSE;
    551  1.1    mrg 	}
    552  1.1    mrg 	Maze[pp->p_y][pp->p_x] = pp->p_over;
    553  1.1    mrg 	x = pp->p_x + pp->p_flyx;
    554  1.1    mrg 	y = pp->p_y + pp->p_flyy;
    555  1.1    mrg 	if (x < 1) {
    556  1.1    mrg 		x = 1 - x;
    557  1.1    mrg 		pp->p_flyx = -pp->p_flyx;
    558  1.1    mrg 	}
    559  1.1    mrg 	else if (x > WIDTH - 2) {
    560  1.1    mrg 		x = (WIDTH - 2) - (x - (WIDTH - 2));
    561  1.1    mrg 		pp->p_flyx = -pp->p_flyx;
    562  1.1    mrg 	}
    563  1.1    mrg 	if (y < 1) {
    564  1.1    mrg 		y = 1 - y;
    565  1.1    mrg 		pp->p_flyy = -pp->p_flyy;
    566  1.1    mrg 	}
    567  1.1    mrg 	else if (y > HEIGHT - 2) {
    568  1.1    mrg 		y = (HEIGHT - 2) - (y - (HEIGHT - 2));
    569  1.1    mrg 		pp->p_flyy = -pp->p_flyy;
    570  1.1    mrg 	}
    571  1.1    mrg again:
    572  1.1    mrg 	switch (Maze[y][x]) {
    573  1.1    mrg 	  default:
    574  1.1    mrg 		switch (rand_num(4)) {
    575  1.1    mrg 		  case 0:
    576  1.1    mrg 			PLUS_DELTA(x, WIDTH - 2);
    577  1.1    mrg 			break;
    578  1.1    mrg 		  case 1:
    579  1.1    mrg 			MINUS_DELTA(x, 1);
    580  1.1    mrg 			break;
    581  1.1    mrg 		  case 2:
    582  1.1    mrg 			PLUS_DELTA(y, HEIGHT - 2);
    583  1.1    mrg 			break;
    584  1.1    mrg 		  case 3:
    585  1.1    mrg 			MINUS_DELTA(y, 1);
    586  1.1    mrg 			break;
    587  1.1    mrg 		}
    588  1.1    mrg 		goto again;
    589  1.1    mrg 	  case WALL1:
    590  1.1    mrg 	  case WALL2:
    591  1.1    mrg 	  case WALL3:
    592  1.1    mrg # ifdef	REFLECT
    593  1.1    mrg 	  case WALL4:
    594  1.1    mrg 	  case WALL5:
    595  1.1    mrg # endif
    596  1.1    mrg # ifdef	RANDOM
    597  1.1    mrg 	  case DOOR:
    598  1.1    mrg # endif
    599  1.1    mrg 		if (pp->p_flying == 0)
    600  1.1    mrg 			pp->p_flying++;
    601  1.1    mrg 		break;
    602  1.1    mrg 	  case SPACE:
    603  1.1    mrg 		break;
    604  1.1    mrg 	}
    605  1.1    mrg 	pp->p_y = y;
    606  1.1    mrg 	pp->p_x = x;
    607  1.1    mrg 	if (pp->p_flying-- == 0) {
    608  1.1    mrg # ifdef BOOTS
    609  1.1    mrg 		if (pp->p_face != BOOT && pp->p_face != BOOT_PAIR) {
    610  1.1    mrg # endif
    611  1.1    mrg 			checkdam(pp, (PLAYER *) NULL, (IDENT *) NULL,
    612  1.1    mrg 				rand_num(pp->p_damage / 5), FALL);
    613  1.1    mrg 			pp->p_face = rand_dir();
    614  1.1    mrg 			showstat(pp);
    615  1.1    mrg # ifdef BOOTS
    616  1.1    mrg 		}
    617  1.1    mrg 		else {
    618  1.1    mrg 			if (Maze[y][x] == BOOT)
    619  1.1    mrg 				pp->p_face = BOOT_PAIR;
    620  1.1    mrg 			Maze[y][x] = SPACE;
    621  1.1    mrg 		}
    622  1.1    mrg # endif
    623  1.1    mrg 	}
    624  1.1    mrg 	pp->p_over = Maze[y][x];
    625  1.1    mrg 	Maze[y][x] = pp->p_face;
    626  1.1    mrg 	showexpl(y, x, pp->p_face);
    627  1.1    mrg }
    628  1.1    mrg 
    629  1.1    mrg /*
    630  1.1    mrg  * chkshot
    631  1.1    mrg  *	Handle explosions
    632  1.1    mrg  */
    633  1.2  lukem static void
    634  1.1    mrg chkshot(bp, next)
    635  1.2  lukem 	BULLET	*bp;
    636  1.2  lukem 	BULLET	*next;
    637  1.1    mrg {
    638  1.2  lukem 	int	y, x;
    639  1.2  lukem 	int	dy, dx, absdy;
    640  1.2  lukem 	int	delta, damage;
    641  1.2  lukem 	char	expl;
    642  1.2  lukem 	PLAYER	*pp;
    643  1.1    mrg 
    644  1.2  lukem 	delta = 0;
    645  1.1    mrg 	switch (bp->b_type) {
    646  1.1    mrg 	  case SHOT:
    647  1.1    mrg 	  case MINE:
    648  1.1    mrg 	  case GRENADE:
    649  1.1    mrg 	  case GMINE:
    650  1.1    mrg 	  case SATCHEL:
    651  1.1    mrg 	  case BOMB:
    652  1.1    mrg 		delta = bp->b_size - 1;
    653  1.1    mrg 		break;
    654  1.1    mrg # ifdef	OOZE
    655  1.1    mrg 	  case SLIME:
    656  1.1    mrg # ifdef VOLCANO
    657  1.1    mrg 	  case LAVA:
    658  1.1    mrg # endif
    659  1.1    mrg 		chkslime(bp, next);
    660  1.1    mrg 		return;
    661  1.1    mrg # endif
    662  1.1    mrg # ifdef DRONE
    663  1.1    mrg 	  case DSHOT:
    664  1.1    mrg 		bp->b_type = SLIME;
    665  1.1    mrg 		chkslime(bp, next);
    666  1.1    mrg 		return;
    667  1.1    mrg # endif
    668  1.1    mrg 	}
    669  1.1    mrg 	for (y = bp->b_y - delta; y <= bp->b_y + delta; y++) {
    670  1.1    mrg 		if (y < 0 || y >= HEIGHT)
    671  1.1    mrg 			continue;
    672  1.1    mrg 		dy = y - bp->b_y;
    673  1.1    mrg 		absdy = (dy < 0) ? -dy : dy;
    674  1.1    mrg 		for (x = bp->b_x - delta; x <= bp->b_x + delta; x++) {
    675  1.1    mrg 			if (x < 0 || x >= WIDTH)
    676  1.1    mrg 				continue;
    677  1.1    mrg 			dx = x - bp->b_x;
    678  1.1    mrg 			if (dx == 0)
    679  1.1    mrg 				expl = (dy == 0) ? '*' : '|';
    680  1.1    mrg 			else if (dy == 0)
    681  1.1    mrg 				expl = '-';
    682  1.1    mrg 			else if (dx == dy)
    683  1.1    mrg 				expl = '\\';
    684  1.1    mrg 			else if (dx == -dy)
    685  1.1    mrg 				expl = '/';
    686  1.1    mrg 			else
    687  1.1    mrg 				expl = '*';
    688  1.1    mrg 			showexpl(y, x, expl);
    689  1.1    mrg 			switch (Maze[y][x]) {
    690  1.1    mrg 			  case LEFTS:
    691  1.1    mrg 			  case RIGHT:
    692  1.1    mrg 			  case ABOVE:
    693  1.1    mrg 			  case BELOW:
    694  1.1    mrg # ifdef FLY
    695  1.1    mrg 			  case FLYER:
    696  1.1    mrg # endif
    697  1.1    mrg 				if (dx < 0)
    698  1.1    mrg 					dx = -dx;
    699  1.1    mrg 				if (absdy > dx)
    700  1.1    mrg 					damage = bp->b_size - absdy;
    701  1.1    mrg 				else
    702  1.1    mrg 					damage = bp->b_size - dx;
    703  1.1    mrg 				pp = play_at(y, x);
    704  1.1    mrg 				checkdam(pp, bp->b_owner, bp->b_score,
    705  1.1    mrg 					damage * MINDAM, bp->b_type);
    706  1.1    mrg 				break;
    707  1.1    mrg 			  case GMINE:
    708  1.1    mrg 			  case MINE:
    709  1.1    mrg 				add_shot((Maze[y][x] == GMINE) ?
    710  1.1    mrg 					GRENADE : SHOT,
    711  1.1    mrg 					y, x, LEFTS,
    712  1.1    mrg 					(Maze[y][x] == GMINE) ?
    713  1.1    mrg 					GRENREQ : BULREQ,
    714  1.1    mrg 					(PLAYER *) NULL, TRUE, SPACE);
    715  1.1    mrg 				Maze[y][x] = SPACE;
    716  1.1    mrg 				break;
    717  1.1    mrg 			}
    718  1.1    mrg 		}
    719  1.1    mrg 	}
    720  1.1    mrg }
    721  1.1    mrg 
    722  1.1    mrg # ifdef	OOZE
    723  1.1    mrg /*
    724  1.1    mrg  * chkslime:
    725  1.1    mrg  *	handle slime shot exploding
    726  1.1    mrg  */
    727  1.2  lukem static void
    728  1.1    mrg chkslime(bp, next)
    729  1.2  lukem 	BULLET	*bp;
    730  1.2  lukem 	BULLET	*next;
    731  1.1    mrg {
    732  1.2  lukem 	BULLET	*nbp;
    733  1.1    mrg 
    734  1.1    mrg 	switch (Maze[bp->b_y][bp->b_x]) {
    735  1.1    mrg 	  case WALL1:
    736  1.1    mrg 	  case WALL2:
    737  1.1    mrg 	  case WALL3:
    738  1.1    mrg # ifdef	REFLECT
    739  1.1    mrg 	  case WALL4:
    740  1.1    mrg 	  case WALL5:
    741  1.1    mrg # endif
    742  1.1    mrg # ifdef	RANDOM
    743  1.1    mrg 	  case DOOR:
    744  1.1    mrg # endif
    745  1.1    mrg 		switch (bp->b_face) {
    746  1.1    mrg 		  case LEFTS:
    747  1.1    mrg 			bp->b_x++;
    748  1.1    mrg 			break;
    749  1.1    mrg 		  case RIGHT:
    750  1.1    mrg 			bp->b_x--;
    751  1.1    mrg 			break;
    752  1.1    mrg 		  case ABOVE:
    753  1.1    mrg 			bp->b_y++;
    754  1.1    mrg 			break;
    755  1.1    mrg 		  case BELOW:
    756  1.1    mrg 			bp->b_y--;
    757  1.1    mrg 			break;
    758  1.1    mrg 		}
    759  1.1    mrg 		break;
    760  1.1    mrg 	}
    761  1.1    mrg 	nbp = (BULLET *) malloc(sizeof (BULLET));
    762  1.1    mrg 	*nbp = *bp;
    763  1.1    mrg # ifdef VOLCANO
    764  1.1    mrg 	move_slime(nbp, nbp->b_type == SLIME ? SLIMESPEED : LAVASPEED, next);
    765  1.1    mrg # else
    766  1.1    mrg 	move_slime(nbp, SLIMESPEED, next);
    767  1.1    mrg # endif
    768  1.1    mrg }
    769  1.1    mrg 
    770  1.1    mrg /*
    771  1.1    mrg  * move_slime:
    772  1.1    mrg  *	move the given slime shot speed times and add it back if
    773  1.1    mrg  *	it hasn't fizzled yet
    774  1.1    mrg  */
    775  1.2  lukem void
    776  1.1    mrg move_slime(bp, speed, next)
    777  1.2  lukem 	BULLET	*bp;
    778  1.2  lukem 	int	speed;
    779  1.2  lukem 	BULLET	*next;
    780  1.1    mrg {
    781  1.2  lukem 	int	i, j, dirmask, count;
    782  1.2  lukem 	PLAYER	*pp;
    783  1.2  lukem 	BULLET	*nbp;
    784  1.1    mrg 
    785  1.1    mrg 	if (speed == 0) {
    786  1.1    mrg 		if (bp->b_charge <= 0)
    787  1.1    mrg 			free((char *) bp);
    788  1.1    mrg 		else
    789  1.1    mrg 			save_bullet(bp);
    790  1.1    mrg 		return;
    791  1.1    mrg 	}
    792  1.1    mrg 
    793  1.1    mrg # ifdef VOLCANO
    794  1.1    mrg 	showexpl(bp->b_y, bp->b_x, bp->b_type == LAVA ? LAVA : '*');
    795  1.1    mrg # else
    796  1.1    mrg 	showexpl(bp->b_y, bp->b_x, '*');
    797  1.1    mrg # endif
    798  1.1    mrg 	switch (Maze[bp->b_y][bp->b_x]) {
    799  1.1    mrg 	  case LEFTS:
    800  1.1    mrg 	  case RIGHT:
    801  1.1    mrg 	  case ABOVE:
    802  1.1    mrg 	  case BELOW:
    803  1.1    mrg # ifdef FLY
    804  1.1    mrg 	  case FLYER:
    805  1.1    mrg # endif
    806  1.1    mrg 		pp = play_at(bp->b_y, bp->b_x);
    807  1.1    mrg 		message(pp, "You've been slimed.");
    808  1.1    mrg 		checkdam(pp, bp->b_owner, bp->b_score, MINDAM, bp->b_type);
    809  1.1    mrg 		break;
    810  1.1    mrg 	  case SHOT:
    811  1.1    mrg 	  case GRENADE:
    812  1.1    mrg 	  case SATCHEL:
    813  1.1    mrg 	  case BOMB:
    814  1.1    mrg # ifdef DRONE
    815  1.1    mrg 	  case DSHOT:
    816  1.1    mrg # endif
    817  1.1    mrg 		explshot(next, bp->b_y, bp->b_x);
    818  1.1    mrg 		explshot(Bullets, bp->b_y, bp->b_x);
    819  1.1    mrg 		break;
    820  1.1    mrg 	}
    821  1.1    mrg 
    822  1.1    mrg 	if (--bp->b_charge <= 0) {
    823  1.1    mrg 		free((char *) bp);
    824  1.1    mrg 		return;
    825  1.1    mrg 	}
    826  1.1    mrg 
    827  1.1    mrg 	dirmask = 0;
    828  1.1    mrg 	count = 0;
    829  1.1    mrg 	switch (bp->b_face) {
    830  1.1    mrg 	  case LEFTS:
    831  1.1    mrg 		if (!iswall(bp->b_y, bp->b_x - 1))
    832  1.1    mrg 			dirmask |= WEST, count++;
    833  1.1    mrg 		if (!iswall(bp->b_y - 1, bp->b_x))
    834  1.1    mrg 			dirmask |= NORTH, count++;
    835  1.1    mrg 		if (!iswall(bp->b_y + 1, bp->b_x))
    836  1.1    mrg 			dirmask |= SOUTH, count++;
    837  1.1    mrg 		if (dirmask == 0)
    838  1.1    mrg 			if (!iswall(bp->b_y, bp->b_x + 1))
    839  1.1    mrg 				dirmask |= EAST, count++;
    840  1.1    mrg 		break;
    841  1.1    mrg 	  case RIGHT:
    842  1.1    mrg 		if (!iswall(bp->b_y, bp->b_x + 1))
    843  1.1    mrg 			dirmask |= EAST, count++;
    844  1.1    mrg 		if (!iswall(bp->b_y - 1, bp->b_x))
    845  1.1    mrg 			dirmask |= NORTH, count++;
    846  1.1    mrg 		if (!iswall(bp->b_y + 1, bp->b_x))
    847  1.1    mrg 			dirmask |= SOUTH, count++;
    848  1.1    mrg 		if (dirmask == 0)
    849  1.1    mrg 			if (!iswall(bp->b_y, bp->b_x - 1))
    850  1.1    mrg 				dirmask |= WEST, count++;
    851  1.1    mrg 		break;
    852  1.1    mrg 	  case ABOVE:
    853  1.1    mrg 		if (!iswall(bp->b_y - 1, bp->b_x))
    854  1.1    mrg 			dirmask |= NORTH, count++;
    855  1.1    mrg 		if (!iswall(bp->b_y, bp->b_x - 1))
    856  1.1    mrg 			dirmask |= WEST, count++;
    857  1.1    mrg 		if (!iswall(bp->b_y, bp->b_x + 1))
    858  1.1    mrg 			dirmask |= EAST, count++;
    859  1.1    mrg 		if (dirmask == 0)
    860  1.1    mrg 			if (!iswall(bp->b_y + 1, bp->b_x))
    861  1.1    mrg 				dirmask |= SOUTH, count++;
    862  1.1    mrg 		break;
    863  1.1    mrg 	  case BELOW:
    864  1.1    mrg 		if (!iswall(bp->b_y + 1, bp->b_x))
    865  1.1    mrg 			dirmask |= SOUTH, count++;
    866  1.1    mrg 		if (!iswall(bp->b_y, bp->b_x - 1))
    867  1.1    mrg 			dirmask |= WEST, count++;
    868  1.1    mrg 		if (!iswall(bp->b_y, bp->b_x + 1))
    869  1.1    mrg 			dirmask |= EAST, count++;
    870  1.1    mrg 		if (dirmask == 0)
    871  1.1    mrg 			if (!iswall(bp->b_y - 1, bp->b_x))
    872  1.1    mrg 				dirmask |= NORTH, count++;
    873  1.1    mrg 		break;
    874  1.1    mrg 	}
    875  1.1    mrg 	if (count == 0) {
    876  1.1    mrg 		/*
    877  1.1    mrg 		 * No place to go.  Just sit here for a while and wait
    878  1.1    mrg 		 * for adjacent squares to clear out.
    879  1.1    mrg 		 */
    880  1.1    mrg 		save_bullet(bp);
    881  1.1    mrg 		return;
    882  1.1    mrg 	}
    883  1.1    mrg 	if (bp->b_charge < count) {
    884  1.1    mrg 		/* Only bp->b_charge paths may be taken */
    885  1.1    mrg 		while (count > bp->b_charge) {
    886  1.1    mrg 			if (dirmask & WEST)
    887  1.1    mrg 				dirmask &= ~WEST;
    888  1.1    mrg 			else if (dirmask & EAST)
    889  1.1    mrg 				dirmask &= ~EAST;
    890  1.1    mrg 			else if (dirmask & NORTH)
    891  1.1    mrg 				dirmask &= ~NORTH;
    892  1.1    mrg 			else if (dirmask & SOUTH)
    893  1.1    mrg 				dirmask &= ~SOUTH;
    894  1.1    mrg 			count--;
    895  1.1    mrg 		}
    896  1.1    mrg 	}
    897  1.1    mrg 
    898  1.1    mrg 	i = bp->b_charge / count;
    899  1.1    mrg 	j = bp->b_charge % count;
    900  1.1    mrg 	if (dirmask & WEST) {
    901  1.1    mrg 		count--;
    902  1.1    mrg 		nbp = create_shot(bp->b_type, bp->b_y, bp->b_x - 1, LEFTS,
    903  1.1    mrg 			i, bp->b_size, bp->b_owner, bp->b_score, TRUE, SPACE);
    904  1.1    mrg 		move_slime(nbp, speed - 1, next);
    905  1.1    mrg 	}
    906  1.1    mrg 	if (dirmask & EAST) {
    907  1.1    mrg 		count--;
    908  1.1    mrg 		nbp = create_shot(bp->b_type, bp->b_y, bp->b_x + 1, RIGHT,
    909  1.1    mrg 			(count < j) ? i + 1 : i, bp->b_size, bp->b_owner,
    910  1.1    mrg 			bp->b_score, TRUE, SPACE);
    911  1.1    mrg 		move_slime(nbp, speed - 1, next);
    912  1.1    mrg 	}
    913  1.1    mrg 	if (dirmask & NORTH) {
    914  1.1    mrg 		count--;
    915  1.1    mrg 		nbp = create_shot(bp->b_type, bp->b_y - 1, bp->b_x, ABOVE,
    916  1.1    mrg 			(count < j) ? i + 1 : i, bp->b_size, bp->b_owner,
    917  1.1    mrg 			bp->b_score, TRUE, SPACE);
    918  1.1    mrg 		move_slime(nbp, speed - 1, next);
    919  1.1    mrg 	}
    920  1.1    mrg 	if (dirmask & SOUTH) {
    921  1.1    mrg 		count--;
    922  1.1    mrg 		nbp = create_shot(bp->b_type, bp->b_y + 1, bp->b_x, BELOW,
    923  1.1    mrg 			(count < j) ? i + 1 : i, bp->b_size, bp->b_owner,
    924  1.1    mrg 			bp->b_score, TRUE, SPACE);
    925  1.1    mrg 		move_slime(nbp, speed - 1, next);
    926  1.1    mrg 	}
    927  1.1    mrg 
    928  1.1    mrg 	free((char *) bp);
    929  1.1    mrg }
    930  1.1    mrg 
    931  1.1    mrg /*
    932  1.1    mrg  * iswall:
    933  1.1    mrg  *	returns whether the given location is a wall
    934  1.1    mrg  */
    935  1.2  lukem static int
    936  1.1    mrg iswall(y, x)
    937  1.2  lukem 	int	y, x;
    938  1.1    mrg {
    939  1.1    mrg 	if (y < 0 || x < 0 || y >= HEIGHT || x >= WIDTH)
    940  1.1    mrg 		return TRUE;
    941  1.1    mrg 	switch (Maze[y][x]) {
    942  1.1    mrg 	  case WALL1:
    943  1.1    mrg 	  case WALL2:
    944  1.1    mrg 	  case WALL3:
    945  1.1    mrg # ifdef	REFLECT
    946  1.1    mrg 	  case WALL4:
    947  1.1    mrg 	  case WALL5:
    948  1.1    mrg # endif
    949  1.1    mrg # ifdef	RANDOM
    950  1.1    mrg 	  case DOOR:
    951  1.1    mrg # endif
    952  1.1    mrg # ifdef OOZE
    953  1.1    mrg 	  case SLIME:
    954  1.1    mrg # ifdef VOLCANO
    955  1.1    mrg 	  case LAVA:
    956  1.1    mrg # endif
    957  1.1    mrg # endif
    958  1.1    mrg 		return TRUE;
    959  1.1    mrg 	}
    960  1.1    mrg 	return FALSE;
    961  1.1    mrg }
    962  1.1    mrg # endif
    963  1.1    mrg 
    964  1.1    mrg /*
    965  1.1    mrg  * zapshot:
    966  1.1    mrg  *	Take a shot out of the air.
    967  1.1    mrg  */
    968  1.2  lukem static void
    969  1.1    mrg zapshot(blist, obp)
    970  1.2  lukem 	BULLET	*blist, *obp;
    971  1.1    mrg {
    972  1.2  lukem 	BULLET	*bp;
    973  1.2  lukem 	FLAG	explode;
    974  1.1    mrg 
    975  1.1    mrg 	explode = FALSE;
    976  1.1    mrg 	for (bp = blist; bp != NULL; bp = bp->b_next) {
    977  1.1    mrg 		if (bp->b_x != obp->b_x || bp->b_y != obp->b_y)
    978  1.1    mrg 			continue;
    979  1.1    mrg 		if (bp->b_face == obp->b_face)
    980  1.1    mrg 			continue;
    981  1.1    mrg 		explode = TRUE;
    982  1.1    mrg 		break;
    983  1.1    mrg 	}
    984  1.1    mrg 	if (!explode)
    985  1.1    mrg 		return;
    986  1.1    mrg 	explshot(blist, obp->b_y, obp->b_x);
    987  1.1    mrg }
    988  1.1    mrg 
    989  1.1    mrg /*
    990  1.1    mrg  * explshot -
    991  1.1    mrg  *	Make all shots at this location blow up
    992  1.1    mrg  */
    993  1.2  lukem void
    994  1.1    mrg explshot(blist, y, x)
    995  1.2  lukem 	BULLET	*blist;
    996  1.2  lukem 	int	y, x;
    997  1.1    mrg {
    998  1.2  lukem 	BULLET	*bp;
    999  1.1    mrg 
   1000  1.1    mrg 	for (bp = blist; bp != NULL; bp = bp->b_next)
   1001  1.1    mrg 		if (bp->b_x == x && bp->b_y == y) {
   1002  1.1    mrg 			bp->b_expl = TRUE;
   1003  1.1    mrg 			if (bp->b_owner != NULL)
   1004  1.1    mrg 				message(bp->b_owner, "Shot intercepted");
   1005  1.1    mrg 		}
   1006  1.1    mrg }
   1007  1.1    mrg 
   1008  1.1    mrg /*
   1009  1.1    mrg  * play_at:
   1010  1.1    mrg  *	Return a pointer to the player at the given location
   1011  1.1    mrg  */
   1012  1.1    mrg PLAYER *
   1013  1.1    mrg play_at(y, x)
   1014  1.2  lukem 	int	y, x;
   1015  1.1    mrg {
   1016  1.2  lukem 	PLAYER	*pp;
   1017  1.1    mrg 
   1018  1.1    mrg 	for (pp = Player; pp < End_player; pp++)
   1019  1.1    mrg 		if (pp->p_x == x && pp->p_y == y)
   1020  1.1    mrg 			return pp;
   1021  1.1    mrg 	fprintf(stderr, "driver: couldn't find player at (%d,%d)\n", x, y);
   1022  1.1    mrg 	abort();
   1023  1.1    mrg 	/* NOTREACHED */
   1024  1.1    mrg }
   1025  1.1    mrg 
   1026  1.1    mrg /*
   1027  1.1    mrg  * opposite:
   1028  1.1    mrg  *	Return TRUE if the bullet direction faces the opposite direction
   1029  1.1    mrg  *	of the player in the maze
   1030  1.1    mrg  */
   1031  1.2  lukem int
   1032  1.1    mrg opposite(face, dir)
   1033  1.2  lukem 	int	face;
   1034  1.2  lukem 	char	dir;
   1035  1.1    mrg {
   1036  1.1    mrg 	switch (face) {
   1037  1.1    mrg 	  case LEFTS:
   1038  1.1    mrg 		return (dir == RIGHT);
   1039  1.1    mrg 	  case RIGHT:
   1040  1.1    mrg 		return (dir == LEFTS);
   1041  1.1    mrg 	  case ABOVE:
   1042  1.1    mrg 		return (dir == BELOW);
   1043  1.1    mrg 	  case BELOW:
   1044  1.1    mrg 		return (dir == ABOVE);
   1045  1.1    mrg 	  default:
   1046  1.1    mrg 		return FALSE;
   1047  1.1    mrg 	}
   1048  1.1    mrg }
   1049  1.1    mrg 
   1050  1.1    mrg /*
   1051  1.1    mrg  * is_bullet:
   1052  1.1    mrg  *	Is there a bullet at the given coordinates?  If so, return
   1053  1.1    mrg  *	a pointer to the bullet, otherwise return NULL
   1054  1.1    mrg  */
   1055  1.1    mrg BULLET *
   1056  1.1    mrg is_bullet(y, x)
   1057  1.2  lukem 	int	y, x;
   1058  1.1    mrg {
   1059  1.2  lukem 	BULLET	*bp;
   1060  1.1    mrg 
   1061  1.1    mrg 	for (bp = Bullets; bp != NULL; bp = bp->b_next)
   1062  1.1    mrg 		if (bp->b_y == y && bp->b_x == x)
   1063  1.1    mrg 			return bp;
   1064  1.1    mrg 	return NULL;
   1065  1.1    mrg }
   1066  1.1    mrg 
   1067  1.1    mrg /*
   1068  1.1    mrg  * fixshots:
   1069  1.1    mrg  *	change the underlying character of the shots at a location
   1070  1.1    mrg  *	to the given character.
   1071  1.1    mrg  */
   1072  1.2  lukem void
   1073  1.1    mrg fixshots(y, x, over)
   1074  1.2  lukem 	int	y, x;
   1075  1.2  lukem 	char	over;
   1076  1.1    mrg {
   1077  1.2  lukem 	BULLET	*bp;
   1078  1.1    mrg 
   1079  1.1    mrg 	for (bp = Bullets; bp != NULL; bp = bp->b_next)
   1080  1.1    mrg 		if (bp->b_y == y && bp->b_x == x)
   1081  1.1    mrg 			bp->b_over = over;
   1082  1.1    mrg }
   1083  1.1    mrg 
   1084  1.1    mrg /*
   1085  1.1    mrg  * find_under:
   1086  1.1    mrg  *	find the underlying character for a bullet when it lands
   1087  1.1    mrg  *	on another bullet.
   1088  1.1    mrg  */
   1089  1.2  lukem static void
   1090  1.1    mrg find_under(blist, bp)
   1091  1.2  lukem 	BULLET	*blist, *bp;
   1092  1.1    mrg {
   1093  1.2  lukem 	BULLET	*nbp;
   1094  1.1    mrg 
   1095  1.1    mrg 	for (nbp = blist; nbp != NULL; nbp = nbp->b_next)
   1096  1.1    mrg 		if (bp->b_y == nbp->b_y && bp->b_x == nbp->b_x) {
   1097  1.1    mrg 			bp->b_over = nbp->b_over;
   1098  1.1    mrg 			break;
   1099  1.1    mrg 		}
   1100  1.1    mrg }
   1101  1.1    mrg 
   1102  1.1    mrg /*
   1103  1.1    mrg  * mark_player:
   1104  1.1    mrg  *	mark a player as under a shot
   1105  1.1    mrg  */
   1106  1.2  lukem static void
   1107  1.1    mrg mark_player(bp)
   1108  1.2  lukem 	BULLET	*bp;
   1109  1.1    mrg {
   1110  1.2  lukem 	PLAYER	*pp;
   1111  1.1    mrg 
   1112  1.1    mrg 	for (pp = Player; pp < End_player; pp++)
   1113  1.1    mrg 		if (pp->p_y == bp->b_y && pp->p_x == bp->b_x) {
   1114  1.1    mrg 			pp->p_undershot = TRUE;
   1115  1.1    mrg 			break;
   1116  1.1    mrg 		}
   1117  1.1    mrg }
   1118  1.1    mrg 
   1119  1.1    mrg # ifdef BOOTS
   1120  1.1    mrg /*
   1121  1.1    mrg  * mark_boot:
   1122  1.1    mrg  *	mark a boot as under a shot
   1123  1.1    mrg  */
   1124  1.2  lukem static void
   1125  1.1    mrg mark_boot(bp)
   1126  1.2  lukem 	BULLET	*bp;
   1127  1.1    mrg {
   1128  1.2  lukem 	PLAYER	*pp;
   1129  1.1    mrg 
   1130  1.1    mrg 	for (pp = Boot; pp < &Boot[NBOOTS]; pp++)
   1131  1.1    mrg 		if (pp->p_y == bp->b_y && pp->p_x == bp->b_x) {
   1132  1.1    mrg 			pp->p_undershot = TRUE;
   1133  1.1    mrg 			break;
   1134  1.1    mrg 		}
   1135  1.1    mrg }
   1136  1.1    mrg # endif
   1137