1 /* $NetBSD: expl.c,v 1.6 2009/07/04 02:37:20 dholland Exp $ */
3 * Copyright (c) 1983-2003, Regents of the University of California.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * + Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * + Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * + Neither the name of the University of California, San Francisco nor
16 * the names of its contributors may be used to endorse or promote
17 * products derived from this software without specific prior written
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
35 __RCSID("$NetBSD: expl.c,v 1.6 2009/07/04 02:37:20 dholland Exp $");
41 static void remove_wall(int, int);
46 * Show the explosions as they currently are
49 showexpl(int y
, int x
, char type
)
54 if (y
< 0 || y
>= HEIGHT
)
56 if (x
< 0 || x
>= WIDTH
)
58 ep
= malloc(sizeof(*ep
));
63 if (Last_expl
== NULL
)
66 Last_expl
->e_next
= ep
;
68 for (pp
= Player
; pp
< End_player
; pp
++) {
69 if (pp
->p_maze
[y
][x
] == type
)
71 pp
->p_maze
[y
][x
] = type
;
76 for (pp
= Monitor
; pp
< End_monitor
; pp
++) {
77 if (pp
->p_maze
[y
][x
] == type
)
79 pp
->p_maze
[y
][x
] = type
;
95 if (y
>= UBOUND
&& y
< DBOUND
&& x
>= LBOUND
&& x
< RBOUND
)
103 * Roll the explosions over, so the next one in the list is at the
115 for (ep
= Expl
[EXPLEN
- 1]; ep
!= NULL
; ep
= nextep
) {
119 if (y
< UBOUND
|| y
>= DBOUND
|| x
< LBOUND
|| x
>= RBOUND
)
123 for (pp
= Player
; pp
< End_player
; pp
++)
124 if (pp
->p_maze
[y
][x
] == ep
->e_char
) {
125 pp
->p_maze
[y
][x
] = c
;
130 for (pp
= Monitor
; pp
< End_monitor
; pp
++)
135 for (x
= EXPLEN
- 1; x
> 0; x
--)
136 Expl
[x
] = Expl
[x
- 1];
137 Last_expl
= Expl
[0] = NULL
;
140 /* There's about 700 walls in the initial maze. So we pick a number
141 * that keeps the maze relatively full. */
144 static REGEN removed
[MAXREMOVE
];
145 static REGEN
*rem_index
= removed
;
148 * remove_wall - add a location where the wall was blown away.
149 * if there is no space left over, put the a wall at
150 * the location currently pointed at.
153 remove_wall(int y
, int x
)
156 #if defined(MONITOR) || defined(FLY)
164 while (r
->r_y
!= 0) {
166 switch (Maze
[r
->r_y
][r
->r_x
]) {
173 save_char
= Maze
[r
->r_y
][r
->r_x
];
177 if (Maze
[r
->r_y
][r
->r_x
] == SPACE
)
180 if (++r
>= &removed
[MAXREMOVE
])
186 /* Slot being used, put back this wall */
188 if (save_char
== SPACE
)
189 Maze
[r
->r_y
][r
->r_x
] = Orig_maze
[r
->r_y
][r
->r_x
];
191 pp
= play_at(r
->r_y
, r
->r_x
);
192 if (pp
->p_flying
>= 0)
193 pp
->p_flying
+= rand_num(10);
195 pp
->p_flying
= rand_num(20);
196 pp
->p_flyx
= 2 * rand_num(6) - 5;
197 pp
->p_flyy
= 2 * rand_num(6) - 5;
199 pp
->p_over
= Orig_maze
[r
->r_y
][r
->r_x
];
201 Maze
[r
->r_y
][r
->r_x
] = FLYER
;
202 showexpl(r
->r_y
, r
->r_x
, FLYER
);
205 Maze
[r
->r_y
][r
->r_x
] = Orig_maze
[r
->r_y
][r
->r_x
];
208 if (rand_num(100) == 0)
209 Maze
[r
->r_y
][r
->r_x
] = DOOR
;
212 if (rand_num(100) == 0) /* one percent of the time */
213 Maze
[r
->r_y
][r
->r_x
] = WALL4
;
216 for (pp
= Monitor
; pp
< End_monitor
; pp
++)
217 check(pp
, r
->r_y
, r
->r_x
);
223 if (++r
>= &removed
[MAXREMOVE
])
230 for (pp
= Monitor
; pp
< End_monitor
; pp
++)
237 * Clear out the walls array
244 for (rp
= removed
; rp
< &removed
[MAXREMOVE
]; rp
++)