expl.c revision 1.3 1 1.3 wiz /* $NetBSD: expl.c,v 1.3 2003/06/11 12:00:22 wiz 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.3 wiz __RCSID("$NetBSD: expl.c,v 1.3 2003/06/11 12:00:22 wiz 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.2 lukem static void remove_wall __P((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.1 mrg showexpl(y, x, type)
50 1.2 lukem int y, x;
51 1.2 lukem char type;
52 1.1 mrg {
53 1.2 lukem PLAYER *pp;
54 1.2 lukem EXPL *ep;
55 1.1 mrg
56 1.1 mrg if (y < 0 || y >= HEIGHT)
57 1.1 mrg return;
58 1.1 mrg if (x < 0 || x >= WIDTH)
59 1.1 mrg return;
60 1.1 mrg ep = (EXPL *) malloc(sizeof (EXPL)); /* NOSTRICT */
61 1.1 mrg ep->e_y = y;
62 1.1 mrg ep->e_x = x;
63 1.1 mrg ep->e_char = type;
64 1.1 mrg ep->e_next = NULL;
65 1.1 mrg if (Last_expl == NULL)
66 1.1 mrg Expl[0] = ep;
67 1.1 mrg else
68 1.1 mrg Last_expl->e_next = ep;
69 1.1 mrg Last_expl = ep;
70 1.1 mrg for (pp = Player; pp < End_player; pp++) {
71 1.1 mrg if (pp->p_maze[y][x] == type)
72 1.1 mrg continue;
73 1.1 mrg pp->p_maze[y][x] = type;
74 1.1 mrg cgoto(pp, y, x);
75 1.1 mrg outch(pp, type);
76 1.1 mrg }
77 1.1 mrg # ifdef MONITOR
78 1.1 mrg for (pp = Monitor; pp < End_monitor; pp++) {
79 1.1 mrg if (pp->p_maze[y][x] == type)
80 1.1 mrg continue;
81 1.1 mrg pp->p_maze[y][x] = type;
82 1.1 mrg cgoto(pp, y, x);
83 1.1 mrg outch(pp, type);
84 1.1 mrg }
85 1.1 mrg # endif
86 1.1 mrg switch (Maze[y][x]) {
87 1.1 mrg case WALL1:
88 1.1 mrg case WALL2:
89 1.1 mrg case WALL3:
90 1.1 mrg # ifdef RANDOM
91 1.1 mrg case DOOR:
92 1.1 mrg # endif
93 1.1 mrg # ifdef REFLECT
94 1.1 mrg case WALL4:
95 1.1 mrg case WALL5:
96 1.1 mrg # endif
97 1.1 mrg if (y >= UBOUND && y < DBOUND && x >= LBOUND && x < RBOUND)
98 1.1 mrg remove_wall(y, x);
99 1.1 mrg break;
100 1.1 mrg }
101 1.1 mrg }
102 1.1 mrg
103 1.1 mrg /*
104 1.1 mrg * rollexpl:
105 1.1 mrg * Roll the explosions over, so the next one in the list is at the
106 1.1 mrg * top
107 1.1 mrg */
108 1.2 lukem void
109 1.1 mrg rollexpl()
110 1.1 mrg {
111 1.2 lukem EXPL *ep;
112 1.2 lukem PLAYER *pp;
113 1.2 lukem int y, x;
114 1.2 lukem char c;
115 1.2 lukem EXPL *nextep;
116 1.1 mrg
117 1.1 mrg for (ep = Expl[EXPLEN - 1]; ep != NULL; ep = nextep) {
118 1.1 mrg nextep = ep->e_next;
119 1.1 mrg y = ep->e_y;
120 1.1 mrg x = ep->e_x;
121 1.1 mrg if (y < UBOUND || y >= DBOUND || x < LBOUND || x >= RBOUND)
122 1.1 mrg c = Maze[y][x];
123 1.1 mrg else
124 1.1 mrg c = SPACE;
125 1.1 mrg for (pp = Player; pp < End_player; pp++)
126 1.1 mrg if (pp->p_maze[y][x] == ep->e_char) {
127 1.1 mrg pp->p_maze[y][x] = c;
128 1.1 mrg cgoto(pp, y, x);
129 1.1 mrg outch(pp, c);
130 1.1 mrg }
131 1.1 mrg # ifdef MONITOR
132 1.1 mrg for (pp = Monitor; pp < End_monitor; pp++)
133 1.1 mrg check(pp, y, x);
134 1.1 mrg # endif
135 1.1 mrg free((char *) ep);
136 1.1 mrg }
137 1.1 mrg for (x = EXPLEN - 1; x > 0; x--)
138 1.1 mrg Expl[x] = Expl[x - 1];
139 1.1 mrg Last_expl = Expl[0] = NULL;
140 1.1 mrg }
141 1.1 mrg
142 1.1 mrg /* There's about 700 walls in the initial maze. So we pick a number
143 1.1 mrg * that keeps the maze relatively full. */
144 1.1 mrg # define MAXREMOVE 40
145 1.1 mrg
146 1.1 mrg static REGEN removed[MAXREMOVE];
147 1.1 mrg static REGEN *rem_index = removed;
148 1.1 mrg
149 1.1 mrg /*
150 1.1 mrg * remove_wall - add a location where the wall was blown away.
151 1.1 mrg * if there is no space left over, put the a wall at
152 1.1 mrg * the location currently pointed at.
153 1.1 mrg */
154 1.2 lukem static void
155 1.1 mrg remove_wall(y, x)
156 1.2 lukem int y, x;
157 1.1 mrg {
158 1.2 lukem REGEN *r;
159 1.1 mrg # if defined(MONITOR) || defined(FLY)
160 1.2 lukem PLAYER *pp;
161 1.1 mrg # endif
162 1.1 mrg # ifdef FLY
163 1.2 lukem char save_char = 0;
164 1.1 mrg # endif
165 1.1 mrg
166 1.1 mrg r = rem_index;
167 1.1 mrg while (r->r_y != 0) {
168 1.1 mrg # ifdef FLY
169 1.1 mrg switch (Maze[r->r_y][r->r_x]) {
170 1.1 mrg case SPACE:
171 1.1 mrg case LEFTS:
172 1.1 mrg case RIGHT:
173 1.1 mrg case ABOVE:
174 1.1 mrg case BELOW:
175 1.1 mrg case FLYER:
176 1.1 mrg save_char = Maze[r->r_y][r->r_x];
177 1.1 mrg goto found;
178 1.1 mrg }
179 1.1 mrg # else
180 1.1 mrg if (Maze[r->r_y][r->r_x] == SPACE)
181 1.1 mrg break;
182 1.1 mrg # endif
183 1.1 mrg if (++r >= &removed[MAXREMOVE])
184 1.1 mrg r = removed;
185 1.1 mrg }
186 1.1 mrg
187 1.1 mrg found:
188 1.1 mrg if (r->r_y != 0) {
189 1.1 mrg /* Slot being used, put back this wall */
190 1.1 mrg # ifdef FLY
191 1.1 mrg if (save_char == SPACE)
192 1.1 mrg Maze[r->r_y][r->r_x] = Orig_maze[r->r_y][r->r_x];
193 1.1 mrg else {
194 1.1 mrg pp = play_at(r->r_y, r->r_x);
195 1.1 mrg if (pp->p_flying >= 0)
196 1.1 mrg pp->p_flying += rand_num(10);
197 1.1 mrg else {
198 1.1 mrg pp->p_flying = rand_num(20);
199 1.1 mrg pp->p_flyx = 2 * rand_num(6) - 5;
200 1.1 mrg pp->p_flyy = 2 * rand_num(6) - 5;
201 1.1 mrg }
202 1.1 mrg pp->p_over = Orig_maze[r->r_y][r->r_x];
203 1.1 mrg pp->p_face = FLYER;
204 1.1 mrg Maze[r->r_y][r->r_x] = FLYER;
205 1.1 mrg showexpl(r->r_y, r->r_x, FLYER);
206 1.1 mrg }
207 1.1 mrg # else
208 1.1 mrg Maze[r->r_y][r->r_x] = Orig_maze[r->r_y][r->r_x];
209 1.1 mrg # endif
210 1.1 mrg # ifdef RANDOM
211 1.1 mrg if (rand_num(100) == 0)
212 1.1 mrg Maze[r->r_y][r->r_x] = DOOR;
213 1.1 mrg # endif
214 1.1 mrg # ifdef REFLECT
215 1.1 mrg if (rand_num(100) == 0) /* one percent of the time */
216 1.1 mrg Maze[r->r_y][r->r_x] = WALL4;
217 1.1 mrg # endif
218 1.1 mrg # ifdef MONITOR
219 1.1 mrg for (pp = Monitor; pp < End_monitor; pp++)
220 1.1 mrg check(pp, r->r_y, r->r_x);
221 1.1 mrg # endif
222 1.1 mrg }
223 1.1 mrg
224 1.1 mrg r->r_y = y;
225 1.1 mrg r->r_x = x;
226 1.1 mrg if (++r >= &removed[MAXREMOVE])
227 1.1 mrg rem_index = removed;
228 1.1 mrg else
229 1.1 mrg rem_index = r;
230 1.1 mrg
231 1.1 mrg Maze[y][x] = SPACE;
232 1.1 mrg # ifdef MONITOR
233 1.1 mrg for (pp = Monitor; pp < End_monitor; pp++)
234 1.1 mrg check(pp, y, x);
235 1.1 mrg # endif
236 1.1 mrg }
237 1.1 mrg
238 1.1 mrg /*
239 1.1 mrg * clearwalls:
240 1.1 mrg * Clear out the walls array
241 1.1 mrg */
242 1.2 lukem void
243 1.1 mrg clearwalls()
244 1.1 mrg {
245 1.2 lukem REGEN *rp;
246 1.1 mrg
247 1.1 mrg for (rp = removed; rp < &removed[MAXREMOVE]; rp++)
248 1.1 mrg rp->r_y = 0;
249 1.1 mrg rem_index = removed;
250 1.1 mrg }
251