Home | History | Annotate | Line # | Download | only in huntd
expl.c revision 1.6
      1  1.6  dholland /*	$NetBSD: expl.c,v 1.6 2009/07/04 02:37:20 dholland Exp $	*/
      2  1.1       mrg /*
      3  1.3       wiz  * Copyright (c) 1983-2003, Regents of the University of California.
      4  1.3       wiz  * All rights reserved.
      5  1.3       wiz  *
      6  1.3       wiz  * Redistribution and use in source and binary forms, with or without
      7  1.3       wiz  * modification, are permitted provided that the following conditions are
      8  1.3       wiz  * met:
      9  1.3       wiz  *
     10  1.3       wiz  * + Redistributions of source code must retain the above copyright
     11  1.3       wiz  *   notice, this list of conditions and the following disclaimer.
     12  1.3       wiz  * + Redistributions in binary form must reproduce the above copyright
     13  1.3       wiz  *   notice, this list of conditions and the following disclaimer in the
     14  1.3       wiz  *   documentation and/or other materials provided with the distribution.
     15  1.3       wiz  * + Neither the name of the University of California, San Francisco nor
     16  1.3       wiz  *   the names of its contributors may be used to endorse or promote
     17  1.3       wiz  *   products derived from this software without specific prior written
     18  1.3       wiz  *   permission.
     19  1.3       wiz  *
     20  1.3       wiz  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
     21  1.3       wiz  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  1.3       wiz  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
     23  1.3       wiz  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     24  1.3       wiz  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     25  1.3       wiz  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     26  1.3       wiz  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  1.3       wiz  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.3       wiz  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  1.3       wiz  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     30  1.3       wiz  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  1.1       mrg  */
     32  1.1       mrg 
     33  1.2     lukem #include <sys/cdefs.h>
     34  1.2     lukem #ifndef lint
     35  1.6  dholland __RCSID("$NetBSD: expl.c,v 1.6 2009/07/04 02:37:20 dholland Exp $");
     36  1.2     lukem #endif /* not lint */
     37  1.2     lukem 
     38  1.2     lukem # include	<stdlib.h>
     39  1.1       mrg # include	"hunt.h"
     40  1.1       mrg 
     41  1.4       jsm static	void	remove_wall(int, int);
     42  1.2     lukem 
     43  1.2     lukem 
     44  1.1       mrg /*
     45  1.1       mrg  * showexpl:
     46  1.1       mrg  *	Show the explosions as they currently are
     47  1.1       mrg  */
     48  1.2     lukem void
     49  1.6  dholland showexpl(int y, int x, char type)
     50  1.1       mrg {
     51  1.2     lukem 	PLAYER	*pp;
     52  1.2     lukem 	EXPL	*ep;
     53  1.1       mrg 
     54  1.1       mrg 	if (y < 0 || y >= HEIGHT)
     55  1.1       mrg 		return;
     56  1.1       mrg 	if (x < 0 || x >= WIDTH)
     57  1.1       mrg 		return;
     58  1.5  dholland 	ep = malloc(sizeof(*ep));
     59  1.1       mrg 	ep->e_y = y;
     60  1.1       mrg 	ep->e_x = x;
     61  1.1       mrg 	ep->e_char = type;
     62  1.1       mrg 	ep->e_next = NULL;
     63  1.1       mrg 	if (Last_expl == NULL)
     64  1.1       mrg 		Expl[0] = ep;
     65  1.1       mrg 	else
     66  1.1       mrg 		Last_expl->e_next = ep;
     67  1.1       mrg 	Last_expl = ep;
     68  1.1       mrg 	for (pp = Player; pp < End_player; pp++) {
     69  1.1       mrg 		if (pp->p_maze[y][x] == type)
     70  1.1       mrg 			continue;
     71  1.1       mrg 		pp->p_maze[y][x] = type;
     72  1.1       mrg 		cgoto(pp, y, x);
     73  1.1       mrg 		outch(pp, type);
     74  1.1       mrg 	}
     75  1.1       mrg # ifdef MONITOR
     76  1.1       mrg 	for (pp = Monitor; pp < End_monitor; pp++) {
     77  1.1       mrg 		if (pp->p_maze[y][x] == type)
     78  1.1       mrg 			continue;
     79  1.1       mrg 		pp->p_maze[y][x] = type;
     80  1.1       mrg 		cgoto(pp, y, x);
     81  1.1       mrg 		outch(pp, type);
     82  1.1       mrg 	}
     83  1.1       mrg # endif
     84  1.1       mrg 	switch (Maze[y][x]) {
     85  1.1       mrg 	  case WALL1:
     86  1.1       mrg 	  case WALL2:
     87  1.1       mrg 	  case WALL3:
     88  1.1       mrg # ifdef RANDOM
     89  1.1       mrg 	  case DOOR:
     90  1.1       mrg # endif
     91  1.1       mrg # ifdef REFLECT
     92  1.1       mrg 	  case WALL4:
     93  1.1       mrg 	  case WALL5:
     94  1.1       mrg # endif
     95  1.1       mrg 		if (y >= UBOUND && y < DBOUND && x >= LBOUND && x < RBOUND)
     96  1.1       mrg 			remove_wall(y, x);
     97  1.1       mrg 		break;
     98  1.1       mrg 	}
     99  1.1       mrg }
    100  1.1       mrg 
    101  1.1       mrg /*
    102  1.1       mrg  * rollexpl:
    103  1.1       mrg  *	Roll the explosions over, so the next one in the list is at the
    104  1.1       mrg  *	top
    105  1.1       mrg  */
    106  1.2     lukem void
    107  1.6  dholland rollexpl(void)
    108  1.1       mrg {
    109  1.2     lukem 	EXPL	*ep;
    110  1.2     lukem 	PLAYER	*pp;
    111  1.2     lukem 	int	y, x;
    112  1.2     lukem 	char	c;
    113  1.2     lukem 	EXPL	*nextep;
    114  1.1       mrg 
    115  1.1       mrg 	for (ep = Expl[EXPLEN - 1]; ep != NULL; ep = nextep) {
    116  1.1       mrg 		nextep = ep->e_next;
    117  1.1       mrg 		y = ep->e_y;
    118  1.1       mrg 		x = ep->e_x;
    119  1.1       mrg 		if (y < UBOUND || y >= DBOUND || x < LBOUND || x >= RBOUND)
    120  1.1       mrg 			c = Maze[y][x];
    121  1.1       mrg 		else
    122  1.1       mrg 			c = SPACE;
    123  1.1       mrg 		for (pp = Player; pp < End_player; pp++)
    124  1.1       mrg 			if (pp->p_maze[y][x] == ep->e_char) {
    125  1.1       mrg 				pp->p_maze[y][x] = c;
    126  1.1       mrg 				cgoto(pp, y, x);
    127  1.1       mrg 				outch(pp, c);
    128  1.1       mrg 			}
    129  1.1       mrg # ifdef MONITOR
    130  1.1       mrg 		for (pp = Monitor; pp < End_monitor; pp++)
    131  1.1       mrg 			check(pp, y, x);
    132  1.1       mrg # endif
    133  1.5  dholland 		free(ep);
    134  1.1       mrg 	}
    135  1.1       mrg 	for (x = EXPLEN - 1; x > 0; x--)
    136  1.1       mrg 		Expl[x] = Expl[x - 1];
    137  1.1       mrg 	Last_expl = Expl[0] = NULL;
    138  1.1       mrg }
    139  1.1       mrg 
    140  1.1       mrg /* There's about 700 walls in the initial maze.  So we pick a number
    141  1.1       mrg  * that keeps the maze relatively full. */
    142  1.1       mrg # define MAXREMOVE	40
    143  1.1       mrg 
    144  1.1       mrg static	REGEN	removed[MAXREMOVE];
    145  1.1       mrg static	REGEN	*rem_index = removed;
    146  1.1       mrg 
    147  1.1       mrg /*
    148  1.1       mrg  * remove_wall - add a location where the wall was blown away.
    149  1.1       mrg  *		 if there is no space left over, put the a wall at
    150  1.1       mrg  *		 the location currently pointed at.
    151  1.1       mrg  */
    152  1.2     lukem static void
    153  1.6  dholland remove_wall(int y, int x)
    154  1.1       mrg {
    155  1.2     lukem 	REGEN	*r;
    156  1.1       mrg # if defined(MONITOR) || defined(FLY)
    157  1.2     lukem 	PLAYER	*pp;
    158  1.1       mrg # endif
    159  1.1       mrg # ifdef	FLY
    160  1.2     lukem 	char	save_char = 0;
    161  1.1       mrg # endif
    162  1.1       mrg 
    163  1.1       mrg 	r = rem_index;
    164  1.1       mrg 	while (r->r_y != 0) {
    165  1.1       mrg # ifdef FLY
    166  1.1       mrg 		switch (Maze[r->r_y][r->r_x]) {
    167  1.1       mrg 		  case SPACE:
    168  1.1       mrg 		  case LEFTS:
    169  1.1       mrg 		  case RIGHT:
    170  1.1       mrg 		  case ABOVE:
    171  1.1       mrg 		  case BELOW:
    172  1.1       mrg 		  case FLYER:
    173  1.1       mrg 			save_char = Maze[r->r_y][r->r_x];
    174  1.1       mrg 			goto found;
    175  1.1       mrg 		}
    176  1.1       mrg # else
    177  1.1       mrg 		if (Maze[r->r_y][r->r_x] == SPACE)
    178  1.1       mrg 			break;
    179  1.1       mrg # endif
    180  1.1       mrg 		if (++r >= &removed[MAXREMOVE])
    181  1.1       mrg 			r = removed;
    182  1.1       mrg 	}
    183  1.1       mrg 
    184  1.1       mrg found:
    185  1.1       mrg 	if (r->r_y != 0) {
    186  1.1       mrg 		/* Slot being used, put back this wall */
    187  1.1       mrg # ifdef FLY
    188  1.1       mrg 		if (save_char == SPACE)
    189  1.1       mrg 			Maze[r->r_y][r->r_x] = Orig_maze[r->r_y][r->r_x];
    190  1.1       mrg 		else {
    191  1.1       mrg 			pp = play_at(r->r_y, r->r_x);
    192  1.1       mrg 			if (pp->p_flying >= 0)
    193  1.1       mrg 				pp->p_flying += rand_num(10);
    194  1.1       mrg 			else {
    195  1.1       mrg 				pp->p_flying = rand_num(20);
    196  1.1       mrg 				pp->p_flyx = 2 * rand_num(6) - 5;
    197  1.1       mrg 				pp->p_flyy = 2 * rand_num(6) - 5;
    198  1.1       mrg 			}
    199  1.1       mrg 			pp->p_over = Orig_maze[r->r_y][r->r_x];
    200  1.1       mrg 			pp->p_face = FLYER;
    201  1.1       mrg 			Maze[r->r_y][r->r_x] = FLYER;
    202  1.1       mrg 			showexpl(r->r_y, r->r_x, FLYER);
    203  1.1       mrg 		}
    204  1.1       mrg # else
    205  1.1       mrg 		Maze[r->r_y][r->r_x] = Orig_maze[r->r_y][r->r_x];
    206  1.1       mrg # endif
    207  1.1       mrg # ifdef RANDOM
    208  1.1       mrg 		if (rand_num(100) == 0)
    209  1.1       mrg 			Maze[r->r_y][r->r_x] = DOOR;
    210  1.1       mrg # endif
    211  1.1       mrg # ifdef REFLECT
    212  1.1       mrg 		if (rand_num(100) == 0)		/* one percent of the time */
    213  1.1       mrg 			Maze[r->r_y][r->r_x] = WALL4;
    214  1.1       mrg # endif
    215  1.1       mrg # ifdef MONITOR
    216  1.1       mrg 		for (pp = Monitor; pp < End_monitor; pp++)
    217  1.1       mrg 			check(pp, r->r_y, r->r_x);
    218  1.1       mrg # endif
    219  1.1       mrg 	}
    220  1.1       mrg 
    221  1.1       mrg 	r->r_y = y;
    222  1.1       mrg 	r->r_x = x;
    223  1.1       mrg 	if (++r >= &removed[MAXREMOVE])
    224  1.1       mrg 		rem_index = removed;
    225  1.1       mrg 	else
    226  1.1       mrg 		rem_index = r;
    227  1.1       mrg 
    228  1.1       mrg 	Maze[y][x] = SPACE;
    229  1.1       mrg # ifdef MONITOR
    230  1.1       mrg 	for (pp = Monitor; pp < End_monitor; pp++)
    231  1.1       mrg 		check(pp, y, x);
    232  1.1       mrg # endif
    233  1.1       mrg }
    234  1.1       mrg 
    235  1.1       mrg /*
    236  1.1       mrg  * clearwalls:
    237  1.1       mrg  *	Clear out the walls array
    238  1.1       mrg  */
    239  1.2     lukem void
    240  1.6  dholland clearwalls(void)
    241  1.1       mrg {
    242  1.2     lukem 	REGEN	*rp;
    243  1.1       mrg 
    244  1.1       mrg 	for (rp = removed; rp < &removed[MAXREMOVE]; rp++)
    245  1.1       mrg 		rp->r_y = 0;
    246  1.1       mrg 	rem_index = removed;
    247  1.1       mrg }
    248