Home | History | Annotate | Line # | Download | only in huntd
expl.c revision 1.1
      1  1.1  mrg /*
      2  1.1  mrg  *  Hunt
      3  1.1  mrg  *  Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold
      4  1.1  mrg  *  San Francisco, California
      5  1.1  mrg  */
      6  1.1  mrg 
      7  1.1  mrg # include	"hunt.h"
      8  1.1  mrg 
      9  1.1  mrg /*
     10  1.1  mrg  * showexpl:
     11  1.1  mrg  *	Show the explosions as they currently are
     12  1.1  mrg  */
     13  1.1  mrg showexpl(y, x, type)
     14  1.1  mrg register int	y, x;
     15  1.1  mrg char		type;
     16  1.1  mrg {
     17  1.1  mrg 	register PLAYER	*pp;
     18  1.1  mrg 	register EXPL	*ep;
     19  1.1  mrg 
     20  1.1  mrg 	if (y < 0 || y >= HEIGHT)
     21  1.1  mrg 		return;
     22  1.1  mrg 	if (x < 0 || x >= WIDTH)
     23  1.1  mrg 		return;
     24  1.1  mrg 	ep = (EXPL *) malloc(sizeof (EXPL));	/* NOSTRICT */
     25  1.1  mrg 	ep->e_y = y;
     26  1.1  mrg 	ep->e_x = x;
     27  1.1  mrg 	ep->e_char = type;
     28  1.1  mrg 	ep->e_next = NULL;
     29  1.1  mrg 	if (Last_expl == NULL)
     30  1.1  mrg 		Expl[0] = ep;
     31  1.1  mrg 	else
     32  1.1  mrg 		Last_expl->e_next = ep;
     33  1.1  mrg 	Last_expl = ep;
     34  1.1  mrg 	for (pp = Player; pp < End_player; pp++) {
     35  1.1  mrg 		if (pp->p_maze[y][x] == type)
     36  1.1  mrg 			continue;
     37  1.1  mrg 		pp->p_maze[y][x] = type;
     38  1.1  mrg 		cgoto(pp, y, x);
     39  1.1  mrg 		outch(pp, type);
     40  1.1  mrg 	}
     41  1.1  mrg # ifdef MONITOR
     42  1.1  mrg 	for (pp = Monitor; pp < End_monitor; pp++) {
     43  1.1  mrg 		if (pp->p_maze[y][x] == type)
     44  1.1  mrg 			continue;
     45  1.1  mrg 		pp->p_maze[y][x] = type;
     46  1.1  mrg 		cgoto(pp, y, x);
     47  1.1  mrg 		outch(pp, type);
     48  1.1  mrg 	}
     49  1.1  mrg # endif
     50  1.1  mrg 	switch (Maze[y][x]) {
     51  1.1  mrg 	  case WALL1:
     52  1.1  mrg 	  case WALL2:
     53  1.1  mrg 	  case WALL3:
     54  1.1  mrg # ifdef RANDOM
     55  1.1  mrg 	  case DOOR:
     56  1.1  mrg # endif
     57  1.1  mrg # ifdef REFLECT
     58  1.1  mrg 	  case WALL4:
     59  1.1  mrg 	  case WALL5:
     60  1.1  mrg # endif
     61  1.1  mrg 		if (y >= UBOUND && y < DBOUND && x >= LBOUND && x < RBOUND)
     62  1.1  mrg 			remove_wall(y, x);
     63  1.1  mrg 		break;
     64  1.1  mrg 	}
     65  1.1  mrg }
     66  1.1  mrg 
     67  1.1  mrg /*
     68  1.1  mrg  * rollexpl:
     69  1.1  mrg  *	Roll the explosions over, so the next one in the list is at the
     70  1.1  mrg  *	top
     71  1.1  mrg  */
     72  1.1  mrg rollexpl()
     73  1.1  mrg {
     74  1.1  mrg 	register EXPL	*ep;
     75  1.1  mrg 	register PLAYER	*pp;
     76  1.1  mrg 	register int	y, x;
     77  1.1  mrg 	register char	c;
     78  1.1  mrg 	register EXPL	*nextep;
     79  1.1  mrg 
     80  1.1  mrg 	for (ep = Expl[EXPLEN - 1]; ep != NULL; ep = nextep) {
     81  1.1  mrg 		nextep = ep->e_next;
     82  1.1  mrg 		y = ep->e_y;
     83  1.1  mrg 		x = ep->e_x;
     84  1.1  mrg 		if (y < UBOUND || y >= DBOUND || x < LBOUND || x >= RBOUND)
     85  1.1  mrg 			c = Maze[y][x];
     86  1.1  mrg 		else
     87  1.1  mrg 			c = SPACE;
     88  1.1  mrg 		for (pp = Player; pp < End_player; pp++)
     89  1.1  mrg 			if (pp->p_maze[y][x] == ep->e_char) {
     90  1.1  mrg 				pp->p_maze[y][x] = c;
     91  1.1  mrg 				cgoto(pp, y, x);
     92  1.1  mrg 				outch(pp, c);
     93  1.1  mrg 			}
     94  1.1  mrg # ifdef MONITOR
     95  1.1  mrg 		for (pp = Monitor; pp < End_monitor; pp++)
     96  1.1  mrg 			check(pp, y, x);
     97  1.1  mrg # endif
     98  1.1  mrg 		free((char *) ep);
     99  1.1  mrg 	}
    100  1.1  mrg 	for (x = EXPLEN - 1; x > 0; x--)
    101  1.1  mrg 		Expl[x] = Expl[x - 1];
    102  1.1  mrg 	Last_expl = Expl[0] = NULL;
    103  1.1  mrg }
    104  1.1  mrg 
    105  1.1  mrg /* There's about 700 walls in the initial maze.  So we pick a number
    106  1.1  mrg  * that keeps the maze relatively full. */
    107  1.1  mrg # define MAXREMOVE	40
    108  1.1  mrg 
    109  1.1  mrg static	REGEN	removed[MAXREMOVE];
    110  1.1  mrg static	REGEN	*rem_index = removed;
    111  1.1  mrg 
    112  1.1  mrg /*
    113  1.1  mrg  * remove_wall - add a location where the wall was blown away.
    114  1.1  mrg  *		 if there is no space left over, put the a wall at
    115  1.1  mrg  *		 the location currently pointed at.
    116  1.1  mrg  */
    117  1.1  mrg remove_wall(y, x)
    118  1.1  mrg int	y, x;
    119  1.1  mrg {
    120  1.1  mrg 	register REGEN	*r;
    121  1.1  mrg # if defined(MONITOR) || defined(FLY)
    122  1.1  mrg 	register PLAYER	*pp;
    123  1.1  mrg # endif
    124  1.1  mrg # ifdef	FLY
    125  1.1  mrg 	register char	save_char;
    126  1.1  mrg # endif
    127  1.1  mrg 
    128  1.1  mrg 	r = rem_index;
    129  1.1  mrg 	while (r->r_y != 0) {
    130  1.1  mrg # ifdef FLY
    131  1.1  mrg 		switch (Maze[r->r_y][r->r_x]) {
    132  1.1  mrg 		  case SPACE:
    133  1.1  mrg 		  case LEFTS:
    134  1.1  mrg 		  case RIGHT:
    135  1.1  mrg 		  case ABOVE:
    136  1.1  mrg 		  case BELOW:
    137  1.1  mrg 		  case FLYER:
    138  1.1  mrg 			save_char = Maze[r->r_y][r->r_x];
    139  1.1  mrg 			goto found;
    140  1.1  mrg 		}
    141  1.1  mrg # else
    142  1.1  mrg 		if (Maze[r->r_y][r->r_x] == SPACE)
    143  1.1  mrg 			break;
    144  1.1  mrg # endif
    145  1.1  mrg 		if (++r >= &removed[MAXREMOVE])
    146  1.1  mrg 			r = removed;
    147  1.1  mrg 	}
    148  1.1  mrg 
    149  1.1  mrg found:
    150  1.1  mrg 	if (r->r_y != 0) {
    151  1.1  mrg 		/* Slot being used, put back this wall */
    152  1.1  mrg # ifdef FLY
    153  1.1  mrg 		if (save_char == SPACE)
    154  1.1  mrg 			Maze[r->r_y][r->r_x] = Orig_maze[r->r_y][r->r_x];
    155  1.1  mrg 		else {
    156  1.1  mrg 			pp = play_at(r->r_y, r->r_x);
    157  1.1  mrg 			if (pp->p_flying >= 0)
    158  1.1  mrg 				pp->p_flying += rand_num(10);
    159  1.1  mrg 			else {
    160  1.1  mrg 				pp->p_flying = rand_num(20);
    161  1.1  mrg 				pp->p_flyx = 2 * rand_num(6) - 5;
    162  1.1  mrg 				pp->p_flyy = 2 * rand_num(6) - 5;
    163  1.1  mrg 			}
    164  1.1  mrg 			pp->p_over = Orig_maze[r->r_y][r->r_x];
    165  1.1  mrg 			pp->p_face = FLYER;
    166  1.1  mrg 			Maze[r->r_y][r->r_x] = FLYER;
    167  1.1  mrg 			showexpl(r->r_y, r->r_x, FLYER);
    168  1.1  mrg 		}
    169  1.1  mrg # else
    170  1.1  mrg 		Maze[r->r_y][r->r_x] = Orig_maze[r->r_y][r->r_x];
    171  1.1  mrg # endif
    172  1.1  mrg # ifdef RANDOM
    173  1.1  mrg 		if (rand_num(100) == 0)
    174  1.1  mrg 			Maze[r->r_y][r->r_x] = DOOR;
    175  1.1  mrg # endif
    176  1.1  mrg # ifdef REFLECT
    177  1.1  mrg 		if (rand_num(100) == 0)		/* one percent of the time */
    178  1.1  mrg 			Maze[r->r_y][r->r_x] = WALL4;
    179  1.1  mrg # endif
    180  1.1  mrg # ifdef MONITOR
    181  1.1  mrg 		for (pp = Monitor; pp < End_monitor; pp++)
    182  1.1  mrg 			check(pp, r->r_y, r->r_x);
    183  1.1  mrg # endif
    184  1.1  mrg 	}
    185  1.1  mrg 
    186  1.1  mrg 	r->r_y = y;
    187  1.1  mrg 	r->r_x = x;
    188  1.1  mrg 	if (++r >= &removed[MAXREMOVE])
    189  1.1  mrg 		rem_index = removed;
    190  1.1  mrg 	else
    191  1.1  mrg 		rem_index = r;
    192  1.1  mrg 
    193  1.1  mrg 	Maze[y][x] = SPACE;
    194  1.1  mrg # ifdef MONITOR
    195  1.1  mrg 	for (pp = Monitor; pp < End_monitor; pp++)
    196  1.1  mrg 		check(pp, y, x);
    197  1.1  mrg # endif
    198  1.1  mrg }
    199  1.1  mrg 
    200  1.1  mrg /*
    201  1.1  mrg  * clearwalls:
    202  1.1  mrg  *	Clear out the walls array
    203  1.1  mrg  */
    204  1.1  mrg clearwalls()
    205  1.1  mrg {
    206  1.1  mrg 	register REGEN	*rp;
    207  1.1  mrg 
    208  1.1  mrg 	for (rp = removed; rp < &removed[MAXREMOVE]; rp++)
    209  1.1  mrg 		rp->r_y = 0;
    210  1.1  mrg 	rem_index = removed;
    211  1.1  mrg }
    212