2 * Copyright (c) 1983-2003, Regents of the University of California.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the University of California, San Francisco nor
15 * the names of its contributors may be used to endorse or promote
16 * products derived from this software without specific prior written
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * $OpenBSD: expl.c,v 1.9 2007/09/04 22:39:31 hshoexer Exp $
32 * $NetBSD: expl.c,v 1.2 1997/10/10 16:33:18 lukem Exp $
33 * $DragonFly: src/games/hunt/huntd/expl.c,v 1.2 2008/09/04 16:12:51 swildner Exp $
43 static void remove_wall(int, int);
44 static void init_removed(void);
49 * Show the explosions as they currently are
52 showexpl(int y, int x, char type)
57 if (y < 0 || y >= HEIGHT)
59 if (x < 0 || x >= WIDTH)
61 ep = (EXPL *) malloc(sizeof (EXPL)); /* NOSTRICT */
63 logit(LOG_ERR, "malloc");
70 if (Last_expl == NULL)
73 Last_expl->e_next = ep;
75 for (pp = Player; pp < End_player; pp++) {
76 if (pp->p_maze[y][x] == type)
78 pp->p_maze[y][x] = type;
82 for (pp = Monitor; pp < End_monitor; pp++) {
83 if (pp->p_maze[y][x] == type)
85 pp->p_maze[y][x] = type;
96 if (y >= UBOUND && y < DBOUND && x >= LBOUND && x < RBOUND)
104 * Roll the explosions over, so the next one in the list is at the
116 for (ep = Expl[EXPLEN - 1]; ep != NULL; ep = nextep) {
120 if (y < UBOUND || y >= DBOUND || x < LBOUND || x >= RBOUND)
124 for (pp = Player; pp < End_player; pp++)
125 if (pp->p_maze[y][x] == ep->e_char) {
126 pp->p_maze[y][x] = c;
130 for (pp = Monitor; pp < End_monitor; pp++)
134 memmove(&Expl[1], &Expl[0], (EXPLEN - 1) * sizeof Expl[0]);
135 /* for (x = EXPLEN - 1; x > 0; x--)
136 Expl[x] = Expl[x - 1]; */
137 Last_expl = Expl[0] = NULL;
145 for (i = EXPLEN - 1; i >= 0; i--)
151 static REGEN *removed = NULL;
152 static REGEN *rem_index = NULL;
157 rem_index = removed = calloc(conf_maxremove, sizeof(REGEN));
158 if (rem_index == NULL) {
159 logit(LOG_ERR, "malloc");
165 * remove_wall - add a location where the wall was blown away.
166 * if there is no space left over, put the a wall at
167 * the location currently pointed at.
170 remove_wall(int y, int x)
180 while (r->r_y != 0) {
181 switch (Maze[r->r_y][r->r_x]) {
188 save_char = Maze[r->r_y][r->r_x];
191 if (++r >= removed + conf_maxremove)
197 /* Slot being used, put back this wall */
198 if (save_char == SPACE)
199 Maze[r->r_y][r->r_x] = Orig_maze[r->r_y][r->r_x];
201 /* We throw the player off the wall: */
202 pp = play_at(r->r_y, r->r_x);
203 if (pp->p_flying >= 0)
204 pp->p_flying += rand_num(conf_flytime / 2);
206 pp->p_flying = rand_num(conf_flytime);
207 pp->p_flyx = 2 * rand_num(conf_flystep + 1) -
209 pp->p_flyy = 2 * rand_num(conf_flystep + 1) -
212 pp->p_over = Orig_maze[r->r_y][r->r_x];
214 Maze[r->r_y][r->r_x] = FLYER;
215 showexpl(r->r_y, r->r_x, FLYER);
217 Maze[r->r_y][r->r_x] = Orig_maze[r->r_y][r->r_x];
218 if (conf_random && rand_num(100) < conf_prandom)
219 Maze[r->r_y][r->r_x] = DOOR;
220 if (conf_reflect && rand_num(100) == conf_preflect)
221 Maze[r->r_y][r->r_x] = WALL4;
222 for (pp = Monitor; pp < End_monitor; pp++)
223 check(pp, r->r_y, r->r_x);
228 if (++r >= removed + conf_maxremove)
234 for (pp = Monitor; pp < End_monitor; pp++)
240 * Clear out the walls array
249 for (rp = removed; rp < removed + conf_maxremove; rp++)