shots.c revision 1.7 1 1.7 dholland /* $NetBSD: shots.c,v 1.7 2009/06/28 21:12:35 dholland Exp $ */
2 1.1 mrg /*
3 1.4 wiz * Copyright (c) 1983-2003, Regents of the University of California.
4 1.4 wiz * All rights reserved.
5 1.4 wiz *
6 1.4 wiz * Redistribution and use in source and binary forms, with or without
7 1.4 wiz * modification, are permitted provided that the following conditions are
8 1.4 wiz * met:
9 1.4 wiz *
10 1.4 wiz * + Redistributions of source code must retain the above copyright
11 1.4 wiz * notice, this list of conditions and the following disclaimer.
12 1.4 wiz * + Redistributions in binary form must reproduce the above copyright
13 1.4 wiz * notice, this list of conditions and the following disclaimer in the
14 1.4 wiz * documentation and/or other materials provided with the distribution.
15 1.4 wiz * + Neither the name of the University of California, San Francisco nor
16 1.4 wiz * the names of its contributors may be used to endorse or promote
17 1.4 wiz * products derived from this software without specific prior written
18 1.4 wiz * permission.
19 1.4 wiz *
20 1.4 wiz * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 1.4 wiz * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.4 wiz * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 1.4 wiz * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 1.4 wiz * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 1.4 wiz * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 1.4 wiz * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.4 wiz * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.4 wiz * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.4 wiz * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 1.4 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.7 dholland __RCSID("$NetBSD: shots.c,v 1.7 2009/06/28 21:12:35 dholland Exp $");
36 1.2 lukem #endif /* not lint */
37 1.2 lukem
38 1.3 lukem # include <err.h>
39 1.2 lukem # include <signal.h>
40 1.2 lukem # include <stdlib.h>
41 1.1 mrg # include "hunt.h"
42 1.1 mrg
43 1.1 mrg # define PLUS_DELTA(x, max) if (x < max) x++; else x--
44 1.1 mrg # define MINUS_DELTA(x, min) if (x > min) x--; else x++
45 1.1 mrg
46 1.5 jsm static void chkshot(BULLET *, BULLET *);
47 1.5 jsm static void chkslime(BULLET *, BULLET *);
48 1.5 jsm static void explshot(BULLET *, int, int);
49 1.5 jsm static void find_under(BULLET *, BULLET *);
50 1.5 jsm static int iswall(int, int);
51 1.5 jsm static void mark_boot(BULLET *);
52 1.5 jsm static void mark_player(BULLET *);
53 1.2 lukem #ifdef DRONE
54 1.5 jsm static void move_drone(BULLET *);
55 1.2 lukem #endif
56 1.5 jsm static void move_flyer(PLAYER *);
57 1.5 jsm static int move_normal_shot(BULLET *);
58 1.5 jsm static void move_slime(BULLET *, int, BULLET *);
59 1.5 jsm static void save_bullet(BULLET *);
60 1.5 jsm static void zapshot(BULLET *, BULLET *);
61 1.2 lukem
62 1.1 mrg /*
63 1.1 mrg * moveshots:
64 1.1 mrg * Move the shots already in the air, taking explosions into account
65 1.1 mrg */
66 1.2 lukem void
67 1.1 mrg moveshots()
68 1.1 mrg {
69 1.2 lukem BULLET *bp, *next;
70 1.2 lukem PLAYER *pp;
71 1.2 lukem int x, y;
72 1.2 lukem BULLET *blist;
73 1.1 mrg
74 1.1 mrg rollexpl();
75 1.1 mrg if (Bullets == NULL)
76 1.1 mrg goto ret;
77 1.1 mrg
78 1.1 mrg /*
79 1.1 mrg * First we move through the bullet list BULSPD times, looking
80 1.1 mrg * for things we may have run into. If we do run into
81 1.1 mrg * something, we set up the explosion and disappear, checking
82 1.1 mrg * for damage to any player who got in the way.
83 1.1 mrg */
84 1.1 mrg
85 1.1 mrg blist = Bullets;
86 1.1 mrg Bullets = NULL;
87 1.1 mrg for (bp = blist; bp != NULL; bp = next) {
88 1.1 mrg next = bp->b_next;
89 1.1 mrg x = bp->b_x;
90 1.1 mrg y = bp->b_y;
91 1.1 mrg Maze[y][x] = bp->b_over;
92 1.1 mrg for (pp = Player; pp < End_player; pp++)
93 1.1 mrg check(pp, y, x);
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
99 1.1 mrg switch (bp->b_type) {
100 1.1 mrg case SHOT:
101 1.1 mrg case GRENADE:
102 1.1 mrg case SATCHEL:
103 1.1 mrg case BOMB:
104 1.1 mrg if (move_normal_shot(bp)) {
105 1.1 mrg bp->b_next = Bullets;
106 1.1 mrg Bullets = bp;
107 1.1 mrg }
108 1.1 mrg break;
109 1.1 mrg # ifdef OOZE
110 1.1 mrg case SLIME:
111 1.1 mrg if (bp->b_expl || move_normal_shot(bp)) {
112 1.1 mrg bp->b_next = Bullets;
113 1.1 mrg Bullets = bp;
114 1.1 mrg }
115 1.1 mrg break;
116 1.1 mrg # endif
117 1.1 mrg # ifdef DRONE
118 1.1 mrg case DSHOT:
119 1.1 mrg if (move_drone(bp)) {
120 1.1 mrg bp->b_next = Bullets;
121 1.1 mrg Bullets = bp;
122 1.1 mrg }
123 1.1 mrg break;
124 1.1 mrg # endif
125 1.1 mrg default:
126 1.1 mrg bp->b_next = Bullets;
127 1.1 mrg Bullets = bp;
128 1.1 mrg break;
129 1.1 mrg }
130 1.1 mrg }
131 1.1 mrg
132 1.1 mrg blist = Bullets;
133 1.1 mrg Bullets = NULL;
134 1.1 mrg for (bp = blist; bp != NULL; bp = next) {
135 1.1 mrg next = bp->b_next;
136 1.1 mrg if (!bp->b_expl) {
137 1.1 mrg save_bullet(bp);
138 1.1 mrg # ifdef MONITOR
139 1.1 mrg for (pp = Monitor; pp < End_monitor; pp++)
140 1.1 mrg check(pp, bp->b_y, bp->b_x);
141 1.1 mrg # endif
142 1.1 mrg # ifdef DRONE
143 1.1 mrg if (bp->b_type == DSHOT)
144 1.1 mrg for (pp = Player; pp < End_player; pp++)
145 1.1 mrg if (pp->p_scan >= 0)
146 1.1 mrg check(pp, bp->b_y, bp->b_x);
147 1.1 mrg # endif
148 1.1 mrg continue;
149 1.1 mrg }
150 1.1 mrg
151 1.1 mrg chkshot(bp, next);
152 1.1 mrg free((char *) bp);
153 1.1 mrg }
154 1.1 mrg
155 1.1 mrg for (pp = Player; pp < End_player; pp++)
156 1.1 mrg Maze[pp->p_y][pp->p_x] = pp->p_face;
157 1.1 mrg
158 1.1 mrg ret:
159 1.1 mrg # ifdef BOOTS
160 1.1 mrg for (pp = Boot; pp < &Boot[NBOOTS]; pp++)
161 1.1 mrg if (pp->p_flying >= 0)
162 1.1 mrg move_flyer(pp);
163 1.1 mrg # endif
164 1.1 mrg for (pp = Player; pp < End_player; pp++) {
165 1.1 mrg # ifdef FLY
166 1.1 mrg if (pp->p_flying >= 0)
167 1.1 mrg move_flyer(pp);
168 1.1 mrg # endif
169 1.1 mrg sendcom(pp, REFRESH); /* Flush out the explosions */
170 1.1 mrg look(pp);
171 1.1 mrg sendcom(pp, REFRESH);
172 1.1 mrg }
173 1.1 mrg # ifdef MONITOR
174 1.1 mrg for (pp = Monitor; pp < End_monitor; pp++)
175 1.1 mrg sendcom(pp, REFRESH);
176 1.1 mrg # endif
177 1.1 mrg
178 1.1 mrg return;
179 1.1 mrg }
180 1.1 mrg
181 1.1 mrg /*
182 1.1 mrg * move_normal_shot:
183 1.1 mrg * Move a normal shot along its trajectory
184 1.1 mrg */
185 1.2 lukem static int
186 1.1 mrg move_normal_shot(bp)
187 1.2 lukem BULLET *bp;
188 1.1 mrg {
189 1.2 lukem int i, x, y;
190 1.2 lukem PLAYER *pp;
191 1.1 mrg
192 1.1 mrg for (i = 0; i < BULSPD; i++) {
193 1.1 mrg if (bp->b_expl)
194 1.1 mrg break;
195 1.1 mrg
196 1.1 mrg x = bp->b_x;
197 1.1 mrg y = bp->b_y;
198 1.1 mrg
199 1.1 mrg switch (bp->b_face) {
200 1.1 mrg case LEFTS:
201 1.1 mrg x--;
202 1.1 mrg break;
203 1.1 mrg case RIGHT:
204 1.1 mrg x++;
205 1.1 mrg break;
206 1.1 mrg case ABOVE:
207 1.1 mrg y--;
208 1.1 mrg break;
209 1.1 mrg case BELOW:
210 1.1 mrg y++;
211 1.1 mrg break;
212 1.1 mrg }
213 1.1 mrg
214 1.1 mrg switch (Maze[y][x]) {
215 1.1 mrg case SHOT:
216 1.1 mrg if (rand_num(100) < 5) {
217 1.1 mrg zapshot(Bullets, bp);
218 1.1 mrg zapshot(bp->b_next, bp);
219 1.1 mrg }
220 1.1 mrg break;
221 1.1 mrg case GRENADE:
222 1.1 mrg if (rand_num(100) < 10) {
223 1.1 mrg zapshot(Bullets, bp);
224 1.1 mrg zapshot(bp->b_next, bp);
225 1.1 mrg }
226 1.1 mrg break;
227 1.1 mrg # ifdef REFLECT
228 1.1 mrg case WALL4: /* reflecting walls */
229 1.1 mrg switch (bp->b_face) {
230 1.1 mrg case LEFTS:
231 1.1 mrg bp->b_face = BELOW;
232 1.1 mrg break;
233 1.1 mrg case RIGHT:
234 1.1 mrg bp->b_face = ABOVE;
235 1.1 mrg break;
236 1.1 mrg case ABOVE:
237 1.1 mrg bp->b_face = RIGHT;
238 1.1 mrg break;
239 1.1 mrg case BELOW:
240 1.1 mrg bp->b_face = LEFTS;
241 1.1 mrg break;
242 1.1 mrg }
243 1.1 mrg Maze[y][x] = WALL5;
244 1.1 mrg # ifdef MONITOR
245 1.1 mrg for (pp = Monitor; pp < End_monitor; pp++)
246 1.1 mrg check(pp, y, x);
247 1.1 mrg # endif
248 1.1 mrg break;
249 1.1 mrg case WALL5:
250 1.1 mrg switch (bp->b_face) {
251 1.1 mrg case LEFTS:
252 1.1 mrg bp->b_face = ABOVE;
253 1.1 mrg break;
254 1.1 mrg case RIGHT:
255 1.1 mrg bp->b_face = BELOW;
256 1.1 mrg break;
257 1.1 mrg case ABOVE:
258 1.1 mrg bp->b_face = LEFTS;
259 1.1 mrg break;
260 1.1 mrg case BELOW:
261 1.1 mrg bp->b_face = RIGHT;
262 1.1 mrg break;
263 1.1 mrg }
264 1.1 mrg Maze[y][x] = WALL4;
265 1.1 mrg # ifdef MONITOR
266 1.1 mrg for (pp = Monitor; pp < End_monitor; pp++)
267 1.1 mrg check(pp, y, x);
268 1.1 mrg # endif
269 1.1 mrg break;
270 1.1 mrg # endif
271 1.1 mrg # ifdef RANDOM
272 1.1 mrg case DOOR:
273 1.1 mrg switch (rand_num(4)) {
274 1.1 mrg case 0:
275 1.1 mrg bp->b_face = ABOVE;
276 1.1 mrg break;
277 1.1 mrg case 1:
278 1.1 mrg bp->b_face = BELOW;
279 1.1 mrg break;
280 1.1 mrg case 2:
281 1.1 mrg bp->b_face = LEFTS;
282 1.1 mrg break;
283 1.1 mrg case 3:
284 1.1 mrg bp->b_face = RIGHT;
285 1.1 mrg break;
286 1.1 mrg }
287 1.1 mrg break;
288 1.1 mrg # endif
289 1.1 mrg # ifdef FLY
290 1.1 mrg case FLYER:
291 1.1 mrg pp = play_at(y, x);
292 1.1 mrg message(pp, "Zing!");
293 1.1 mrg break;
294 1.1 mrg # endif
295 1.1 mrg case LEFTS:
296 1.1 mrg case RIGHT:
297 1.1 mrg case BELOW:
298 1.1 mrg case ABOVE:
299 1.1 mrg /*
300 1.1 mrg * give the person a chance to catch a
301 1.1 mrg * grenade if s/he is facing it
302 1.1 mrg */
303 1.1 mrg pp = play_at(y, x);
304 1.1 mrg pp->p_ident->i_shot += bp->b_charge;
305 1.1 mrg if (opposite(bp->b_face, Maze[y][x])) {
306 1.1 mrg if (rand_num(100) < 10) {
307 1.1 mrg if (bp->b_owner != NULL)
308 1.1 mrg message(bp->b_owner,
309 1.1 mrg "Your charge was absorbed!");
310 1.1 mrg if (bp->b_score != NULL)
311 1.1 mrg bp->b_score->i_robbed += bp->b_charge;
312 1.1 mrg pp->p_ammo += bp->b_charge;
313 1.1 mrg if (pp->p_damage + bp->b_size * MINDAM
314 1.1 mrg > pp->p_damcap)
315 1.1 mrg pp->p_ident->i_saved++;
316 1.1 mrg message(pp, "Absorbed charge (good shield!)");
317 1.1 mrg pp->p_ident->i_absorbed += bp->b_charge;
318 1.1 mrg free((char *) bp);
319 1.7 dholland (void) snprintf(Buf, sizeof(Buf),
320 1.7 dholland "%3d", pp->p_ammo);
321 1.1 mrg cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
322 1.1 mrg outstr(pp, Buf, 3);
323 1.1 mrg return FALSE;
324 1.1 mrg }
325 1.1 mrg pp->p_ident->i_faced += bp->b_charge;
326 1.1 mrg }
327 1.1 mrg /*
328 1.1 mrg * Small chance that the bullet just misses the
329 1.1 mrg * person. If so, the bullet just goes on its
330 1.1 mrg * merry way without exploding.
331 1.1 mrg */
332 1.1 mrg if (rand_num(100) < 5) {
333 1.1 mrg pp->p_ident->i_ducked += bp->b_charge;
334 1.1 mrg if (pp->p_damage + bp->b_size * MINDAM
335 1.1 mrg > pp->p_damcap)
336 1.1 mrg pp->p_ident->i_saved++;
337 1.1 mrg if (bp->b_score != NULL)
338 1.1 mrg bp->b_score->i_missed += bp->b_charge;
339 1.1 mrg message(pp, "Zing!");
340 1.1 mrg if (bp->b_owner == NULL)
341 1.1 mrg break;
342 1.6 abs message(bp->b_owner, bp->b_score &&
343 1.1 mrg ((bp->b_score->i_missed & 0x7) == 0x7) ?
344 1.1 mrg "My! What a bad shot you are!" :
345 1.1 mrg "Missed him");
346 1.1 mrg break;
347 1.1 mrg }
348 1.1 mrg /*
349 1.1 mrg * The shot hit that sucker! Blow it up.
350 1.1 mrg */
351 1.1 mrg /* FALLTHROUGH */
352 1.1 mrg # ifndef RANDOM
353 1.1 mrg case DOOR:
354 1.1 mrg # endif
355 1.1 mrg case WALL1:
356 1.1 mrg case WALL2:
357 1.1 mrg case WALL3:
358 1.1 mrg bp->b_expl = TRUE;
359 1.1 mrg break;
360 1.1 mrg }
361 1.1 mrg
362 1.1 mrg bp->b_x = x;
363 1.1 mrg bp->b_y = y;
364 1.1 mrg }
365 1.1 mrg return TRUE;
366 1.1 mrg }
367 1.1 mrg
368 1.1 mrg # ifdef DRONE
369 1.1 mrg /*
370 1.1 mrg * move_drone:
371 1.1 mrg * Move the drone to the next square
372 1.1 mrg */
373 1.2 lukem static void
374 1.1 mrg move_drone(bp)
375 1.2 lukem BULLET *bp;
376 1.1 mrg {
377 1.2 lukem int mask, count;
378 1.2 lukem int n, dir;
379 1.2 lukem PLAYER *pp;
380 1.1 mrg
381 1.1 mrg /*
382 1.1 mrg * See if we can give someone a blast
383 1.1 mrg */
384 1.1 mrg if (isplayer(Maze[bp->b_y][bp->b_x - 1])) {
385 1.1 mrg dir = WEST;
386 1.1 mrg goto drone_move;
387 1.1 mrg }
388 1.1 mrg if (isplayer(Maze[bp->b_y - 1][bp->b_x])) {
389 1.1 mrg dir = NORTH;
390 1.1 mrg goto drone_move;
391 1.1 mrg }
392 1.1 mrg if (isplayer(Maze[bp->b_y + 1][bp->b_x])) {
393 1.1 mrg dir = SOUTH;
394 1.1 mrg goto drone_move;
395 1.1 mrg }
396 1.1 mrg if (isplayer(Maze[bp->b_y][bp->b_x + 1])) {
397 1.1 mrg dir = EAST;
398 1.1 mrg goto drone_move;
399 1.1 mrg }
400 1.1 mrg
401 1.1 mrg /*
402 1.1 mrg * Find out what directions are clear
403 1.1 mrg */
404 1.1 mrg mask = count = 0;
405 1.1 mrg if (!iswall(bp->b_y, bp->b_x - 1))
406 1.1 mrg mask |= WEST, count++;
407 1.1 mrg if (!iswall(bp->b_y - 1, bp->b_x))
408 1.1 mrg mask |= NORTH, count++;
409 1.1 mrg if (!iswall(bp->b_y + 1, bp->b_x))
410 1.1 mrg mask |= SOUTH, count++;
411 1.1 mrg if (!iswall(bp->b_y, bp->b_x + 1))
412 1.1 mrg mask |= EAST, count++;
413 1.1 mrg
414 1.1 mrg /*
415 1.1 mrg * All blocked up, just you wait
416 1.1 mrg */
417 1.1 mrg if (count == 0)
418 1.1 mrg return TRUE;
419 1.1 mrg
420 1.1 mrg /*
421 1.1 mrg * Only one way to go.
422 1.1 mrg */
423 1.1 mrg if (count == 1) {
424 1.1 mrg dir = mask;
425 1.1 mrg goto drone_move;
426 1.1 mrg }
427 1.1 mrg
428 1.1 mrg /*
429 1.1 mrg * Get rid of the direction that we came from
430 1.1 mrg */
431 1.1 mrg switch (bp->b_face) {
432 1.1 mrg case LEFTS:
433 1.1 mrg if (mask & EAST)
434 1.1 mrg mask &= ~EAST, count--;
435 1.1 mrg break;
436 1.1 mrg case RIGHT:
437 1.1 mrg if (mask & WEST)
438 1.1 mrg mask &= ~WEST, count--;
439 1.1 mrg break;
440 1.1 mrg case ABOVE:
441 1.1 mrg if (mask & SOUTH)
442 1.1 mrg mask &= ~SOUTH, count--;
443 1.1 mrg break;
444 1.1 mrg case BELOW:
445 1.1 mrg if (mask & NORTH)
446 1.1 mrg mask &= ~NORTH, count--;
447 1.1 mrg break;
448 1.1 mrg }
449 1.1 mrg
450 1.1 mrg /*
451 1.1 mrg * Pick one of the remaining directions
452 1.1 mrg */
453 1.1 mrg n = rand_num(count);
454 1.1 mrg if (n >= 0 && mask & NORTH)
455 1.1 mrg dir = NORTH, n--;
456 1.1 mrg if (n >= 0 && mask & SOUTH)
457 1.1 mrg dir = SOUTH, n--;
458 1.1 mrg if (n >= 0 && mask & EAST)
459 1.1 mrg dir = EAST, n--;
460 1.1 mrg if (n >= 0 && mask & WEST)
461 1.1 mrg dir = WEST, n--;
462 1.1 mrg
463 1.1 mrg /*
464 1.1 mrg * Now that we know the direction of movement,
465 1.1 mrg * just update the position of the drone
466 1.1 mrg */
467 1.1 mrg drone_move:
468 1.1 mrg switch (dir) {
469 1.1 mrg case WEST:
470 1.1 mrg bp->b_x--;
471 1.1 mrg bp->b_face = LEFTS;
472 1.1 mrg break;
473 1.1 mrg case EAST:
474 1.1 mrg bp->b_x++;
475 1.1 mrg bp->b_face = RIGHT;
476 1.1 mrg break;
477 1.1 mrg case NORTH:
478 1.1 mrg bp->b_y--;
479 1.1 mrg bp->b_face = ABOVE;
480 1.1 mrg break;
481 1.1 mrg case SOUTH:
482 1.1 mrg bp->b_y++;
483 1.1 mrg bp->b_face = BELOW;
484 1.1 mrg break;
485 1.1 mrg }
486 1.1 mrg switch (Maze[bp->b_y][bp->b_x]) {
487 1.1 mrg case LEFTS:
488 1.1 mrg case RIGHT:
489 1.1 mrg case BELOW:
490 1.1 mrg case ABOVE:
491 1.1 mrg /*
492 1.1 mrg * give the person a chance to catch a
493 1.1 mrg * drone if s/he is facing it
494 1.1 mrg */
495 1.1 mrg if (rand_num(100) < 1 &&
496 1.1 mrg opposite(bp->b_face, Maze[bp->b_y][bp->b_x])) {
497 1.1 mrg pp = play_at(bp->b_y, bp->b_x);
498 1.1 mrg pp->p_ammo += bp->b_charge;
499 1.1 mrg message(pp, "**** Absorbed drone ****");
500 1.1 mrg free((char *) bp);
501 1.7 dholland (void) snprintf(Buf, sizeof(buf), "%3d", pp->p_ammo);
502 1.1 mrg cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
503 1.1 mrg outstr(pp, Buf, 3);
504 1.1 mrg return FALSE;
505 1.1 mrg }
506 1.1 mrg bp->b_expl = TRUE;
507 1.1 mrg break;
508 1.1 mrg }
509 1.1 mrg return TRUE;
510 1.1 mrg }
511 1.1 mrg # endif
512 1.1 mrg
513 1.1 mrg /*
514 1.1 mrg * save_bullet:
515 1.1 mrg * Put this bullet back onto the bullet list
516 1.1 mrg */
517 1.2 lukem static void
518 1.1 mrg save_bullet(bp)
519 1.2 lukem BULLET *bp;
520 1.1 mrg {
521 1.1 mrg bp->b_over = Maze[bp->b_y][bp->b_x];
522 1.1 mrg switch (bp->b_over) {
523 1.1 mrg case SHOT:
524 1.1 mrg case GRENADE:
525 1.1 mrg case SATCHEL:
526 1.1 mrg case BOMB:
527 1.1 mrg # ifdef OOZE
528 1.1 mrg case SLIME:
529 1.1 mrg # ifdef VOLCANO
530 1.1 mrg case LAVA:
531 1.1 mrg # endif
532 1.1 mrg # endif
533 1.1 mrg # ifdef DRONE
534 1.1 mrg case DSHOT:
535 1.1 mrg # endif
536 1.1 mrg find_under(Bullets, bp);
537 1.1 mrg break;
538 1.1 mrg }
539 1.1 mrg
540 1.1 mrg switch (bp->b_over) {
541 1.1 mrg case LEFTS:
542 1.1 mrg case RIGHT:
543 1.1 mrg case ABOVE:
544 1.1 mrg case BELOW:
545 1.1 mrg # ifdef FLY
546 1.1 mrg case FLYER:
547 1.1 mrg # endif
548 1.1 mrg mark_player(bp);
549 1.1 mrg break;
550 1.1 mrg # ifdef BOOTS
551 1.1 mrg case BOOT:
552 1.1 mrg case BOOT_PAIR:
553 1.1 mrg mark_boot(bp);
554 1.1 mrg # endif
555 1.1 mrg
556 1.1 mrg default:
557 1.1 mrg Maze[bp->b_y][bp->b_x] = bp->b_type;
558 1.1 mrg break;
559 1.1 mrg }
560 1.1 mrg
561 1.1 mrg bp->b_next = Bullets;
562 1.1 mrg Bullets = bp;
563 1.1 mrg }
564 1.1 mrg
565 1.1 mrg /*
566 1.1 mrg * move_flyer:
567 1.1 mrg * Update the position of a player in flight
568 1.1 mrg */
569 1.2 lukem static void
570 1.1 mrg move_flyer(pp)
571 1.2 lukem PLAYER *pp;
572 1.1 mrg {
573 1.2 lukem int x, y;
574 1.1 mrg
575 1.1 mrg if (pp->p_undershot) {
576 1.1 mrg fixshots(pp->p_y, pp->p_x, pp->p_over);
577 1.1 mrg pp->p_undershot = FALSE;
578 1.1 mrg }
579 1.1 mrg Maze[pp->p_y][pp->p_x] = pp->p_over;
580 1.1 mrg x = pp->p_x + pp->p_flyx;
581 1.1 mrg y = pp->p_y + pp->p_flyy;
582 1.1 mrg if (x < 1) {
583 1.1 mrg x = 1 - x;
584 1.1 mrg pp->p_flyx = -pp->p_flyx;
585 1.1 mrg }
586 1.1 mrg else if (x > WIDTH - 2) {
587 1.1 mrg x = (WIDTH - 2) - (x - (WIDTH - 2));
588 1.1 mrg pp->p_flyx = -pp->p_flyx;
589 1.1 mrg }
590 1.1 mrg if (y < 1) {
591 1.1 mrg y = 1 - y;
592 1.1 mrg pp->p_flyy = -pp->p_flyy;
593 1.1 mrg }
594 1.1 mrg else if (y > HEIGHT - 2) {
595 1.1 mrg y = (HEIGHT - 2) - (y - (HEIGHT - 2));
596 1.1 mrg pp->p_flyy = -pp->p_flyy;
597 1.1 mrg }
598 1.1 mrg again:
599 1.1 mrg switch (Maze[y][x]) {
600 1.1 mrg default:
601 1.1 mrg switch (rand_num(4)) {
602 1.1 mrg case 0:
603 1.1 mrg PLUS_DELTA(x, WIDTH - 2);
604 1.1 mrg break;
605 1.1 mrg case 1:
606 1.1 mrg MINUS_DELTA(x, 1);
607 1.1 mrg break;
608 1.1 mrg case 2:
609 1.1 mrg PLUS_DELTA(y, HEIGHT - 2);
610 1.1 mrg break;
611 1.1 mrg case 3:
612 1.1 mrg MINUS_DELTA(y, 1);
613 1.1 mrg break;
614 1.1 mrg }
615 1.1 mrg goto again;
616 1.1 mrg case WALL1:
617 1.1 mrg case WALL2:
618 1.1 mrg case WALL3:
619 1.1 mrg # ifdef REFLECT
620 1.1 mrg case WALL4:
621 1.1 mrg case WALL5:
622 1.1 mrg # endif
623 1.1 mrg # ifdef RANDOM
624 1.1 mrg case DOOR:
625 1.1 mrg # endif
626 1.1 mrg if (pp->p_flying == 0)
627 1.1 mrg pp->p_flying++;
628 1.1 mrg break;
629 1.1 mrg case SPACE:
630 1.1 mrg break;
631 1.1 mrg }
632 1.1 mrg pp->p_y = y;
633 1.1 mrg pp->p_x = x;
634 1.1 mrg if (pp->p_flying-- == 0) {
635 1.1 mrg # ifdef BOOTS
636 1.1 mrg if (pp->p_face != BOOT && pp->p_face != BOOT_PAIR) {
637 1.1 mrg # endif
638 1.1 mrg checkdam(pp, (PLAYER *) NULL, (IDENT *) NULL,
639 1.1 mrg rand_num(pp->p_damage / 5), FALL);
640 1.1 mrg pp->p_face = rand_dir();
641 1.1 mrg showstat(pp);
642 1.1 mrg # ifdef BOOTS
643 1.1 mrg }
644 1.1 mrg else {
645 1.1 mrg if (Maze[y][x] == BOOT)
646 1.1 mrg pp->p_face = BOOT_PAIR;
647 1.1 mrg Maze[y][x] = SPACE;
648 1.1 mrg }
649 1.1 mrg # endif
650 1.1 mrg }
651 1.1 mrg pp->p_over = Maze[y][x];
652 1.1 mrg Maze[y][x] = pp->p_face;
653 1.1 mrg showexpl(y, x, pp->p_face);
654 1.1 mrg }
655 1.1 mrg
656 1.1 mrg /*
657 1.1 mrg * chkshot
658 1.1 mrg * Handle explosions
659 1.1 mrg */
660 1.2 lukem static void
661 1.1 mrg chkshot(bp, next)
662 1.2 lukem BULLET *bp;
663 1.2 lukem BULLET *next;
664 1.1 mrg {
665 1.2 lukem int y, x;
666 1.2 lukem int dy, dx, absdy;
667 1.2 lukem int delta, damage;
668 1.2 lukem char expl;
669 1.2 lukem PLAYER *pp;
670 1.1 mrg
671 1.2 lukem delta = 0;
672 1.1 mrg switch (bp->b_type) {
673 1.1 mrg case SHOT:
674 1.1 mrg case MINE:
675 1.1 mrg case GRENADE:
676 1.1 mrg case GMINE:
677 1.1 mrg case SATCHEL:
678 1.1 mrg case BOMB:
679 1.1 mrg delta = bp->b_size - 1;
680 1.1 mrg break;
681 1.1 mrg # ifdef OOZE
682 1.1 mrg case SLIME:
683 1.1 mrg # ifdef VOLCANO
684 1.1 mrg case LAVA:
685 1.1 mrg # endif
686 1.1 mrg chkslime(bp, next);
687 1.1 mrg return;
688 1.1 mrg # endif
689 1.1 mrg # ifdef DRONE
690 1.1 mrg case DSHOT:
691 1.1 mrg bp->b_type = SLIME;
692 1.1 mrg chkslime(bp, next);
693 1.1 mrg return;
694 1.1 mrg # endif
695 1.1 mrg }
696 1.1 mrg for (y = bp->b_y - delta; y <= bp->b_y + delta; y++) {
697 1.1 mrg if (y < 0 || y >= HEIGHT)
698 1.1 mrg continue;
699 1.1 mrg dy = y - bp->b_y;
700 1.1 mrg absdy = (dy < 0) ? -dy : dy;
701 1.1 mrg for (x = bp->b_x - delta; x <= bp->b_x + delta; x++) {
702 1.1 mrg if (x < 0 || x >= WIDTH)
703 1.1 mrg continue;
704 1.1 mrg dx = x - bp->b_x;
705 1.1 mrg if (dx == 0)
706 1.1 mrg expl = (dy == 0) ? '*' : '|';
707 1.1 mrg else if (dy == 0)
708 1.1 mrg expl = '-';
709 1.1 mrg else if (dx == dy)
710 1.1 mrg expl = '\\';
711 1.1 mrg else if (dx == -dy)
712 1.1 mrg expl = '/';
713 1.1 mrg else
714 1.1 mrg expl = '*';
715 1.1 mrg showexpl(y, x, expl);
716 1.1 mrg switch (Maze[y][x]) {
717 1.1 mrg case LEFTS:
718 1.1 mrg case RIGHT:
719 1.1 mrg case ABOVE:
720 1.1 mrg case BELOW:
721 1.1 mrg # ifdef FLY
722 1.1 mrg case FLYER:
723 1.1 mrg # endif
724 1.1 mrg if (dx < 0)
725 1.1 mrg dx = -dx;
726 1.1 mrg if (absdy > dx)
727 1.1 mrg damage = bp->b_size - absdy;
728 1.1 mrg else
729 1.1 mrg damage = bp->b_size - dx;
730 1.1 mrg pp = play_at(y, x);
731 1.1 mrg checkdam(pp, bp->b_owner, bp->b_score,
732 1.1 mrg damage * MINDAM, bp->b_type);
733 1.1 mrg break;
734 1.1 mrg case GMINE:
735 1.1 mrg case MINE:
736 1.1 mrg add_shot((Maze[y][x] == GMINE) ?
737 1.1 mrg GRENADE : SHOT,
738 1.1 mrg y, x, LEFTS,
739 1.1 mrg (Maze[y][x] == GMINE) ?
740 1.1 mrg GRENREQ : BULREQ,
741 1.1 mrg (PLAYER *) NULL, TRUE, SPACE);
742 1.1 mrg Maze[y][x] = SPACE;
743 1.1 mrg break;
744 1.1 mrg }
745 1.1 mrg }
746 1.1 mrg }
747 1.1 mrg }
748 1.1 mrg
749 1.1 mrg # ifdef OOZE
750 1.1 mrg /*
751 1.1 mrg * chkslime:
752 1.1 mrg * handle slime shot exploding
753 1.1 mrg */
754 1.2 lukem static void
755 1.1 mrg chkslime(bp, next)
756 1.2 lukem BULLET *bp;
757 1.2 lukem BULLET *next;
758 1.1 mrg {
759 1.2 lukem BULLET *nbp;
760 1.1 mrg
761 1.1 mrg switch (Maze[bp->b_y][bp->b_x]) {
762 1.1 mrg case WALL1:
763 1.1 mrg case WALL2:
764 1.1 mrg case WALL3:
765 1.1 mrg # ifdef REFLECT
766 1.1 mrg case WALL4:
767 1.1 mrg case WALL5:
768 1.1 mrg # endif
769 1.1 mrg # ifdef RANDOM
770 1.1 mrg case DOOR:
771 1.1 mrg # endif
772 1.1 mrg switch (bp->b_face) {
773 1.1 mrg case LEFTS:
774 1.1 mrg bp->b_x++;
775 1.1 mrg break;
776 1.1 mrg case RIGHT:
777 1.1 mrg bp->b_x--;
778 1.1 mrg break;
779 1.1 mrg case ABOVE:
780 1.1 mrg bp->b_y++;
781 1.1 mrg break;
782 1.1 mrg case BELOW:
783 1.1 mrg bp->b_y--;
784 1.1 mrg break;
785 1.1 mrg }
786 1.1 mrg break;
787 1.1 mrg }
788 1.1 mrg nbp = (BULLET *) malloc(sizeof (BULLET));
789 1.1 mrg *nbp = *bp;
790 1.1 mrg # ifdef VOLCANO
791 1.1 mrg move_slime(nbp, nbp->b_type == SLIME ? SLIMESPEED : LAVASPEED, next);
792 1.1 mrg # else
793 1.1 mrg move_slime(nbp, SLIMESPEED, next);
794 1.1 mrg # endif
795 1.1 mrg }
796 1.1 mrg
797 1.1 mrg /*
798 1.1 mrg * move_slime:
799 1.1 mrg * move the given slime shot speed times and add it back if
800 1.1 mrg * it hasn't fizzled yet
801 1.1 mrg */
802 1.2 lukem void
803 1.1 mrg move_slime(bp, speed, next)
804 1.2 lukem BULLET *bp;
805 1.2 lukem int speed;
806 1.2 lukem BULLET *next;
807 1.1 mrg {
808 1.2 lukem int i, j, dirmask, count;
809 1.2 lukem PLAYER *pp;
810 1.2 lukem BULLET *nbp;
811 1.1 mrg
812 1.1 mrg if (speed == 0) {
813 1.1 mrg if (bp->b_charge <= 0)
814 1.1 mrg free((char *) bp);
815 1.1 mrg else
816 1.1 mrg save_bullet(bp);
817 1.1 mrg return;
818 1.1 mrg }
819 1.1 mrg
820 1.1 mrg # ifdef VOLCANO
821 1.1 mrg showexpl(bp->b_y, bp->b_x, bp->b_type == LAVA ? LAVA : '*');
822 1.1 mrg # else
823 1.1 mrg showexpl(bp->b_y, bp->b_x, '*');
824 1.1 mrg # endif
825 1.1 mrg switch (Maze[bp->b_y][bp->b_x]) {
826 1.1 mrg case LEFTS:
827 1.1 mrg case RIGHT:
828 1.1 mrg case ABOVE:
829 1.1 mrg case BELOW:
830 1.1 mrg # ifdef FLY
831 1.1 mrg case FLYER:
832 1.1 mrg # endif
833 1.1 mrg pp = play_at(bp->b_y, bp->b_x);
834 1.1 mrg message(pp, "You've been slimed.");
835 1.1 mrg checkdam(pp, bp->b_owner, bp->b_score, MINDAM, bp->b_type);
836 1.1 mrg break;
837 1.1 mrg case SHOT:
838 1.1 mrg case GRENADE:
839 1.1 mrg case SATCHEL:
840 1.1 mrg case BOMB:
841 1.1 mrg # ifdef DRONE
842 1.1 mrg case DSHOT:
843 1.1 mrg # endif
844 1.1 mrg explshot(next, bp->b_y, bp->b_x);
845 1.1 mrg explshot(Bullets, bp->b_y, bp->b_x);
846 1.1 mrg break;
847 1.1 mrg }
848 1.1 mrg
849 1.1 mrg if (--bp->b_charge <= 0) {
850 1.1 mrg free((char *) bp);
851 1.1 mrg return;
852 1.1 mrg }
853 1.1 mrg
854 1.1 mrg dirmask = 0;
855 1.1 mrg count = 0;
856 1.1 mrg switch (bp->b_face) {
857 1.1 mrg case LEFTS:
858 1.1 mrg if (!iswall(bp->b_y, bp->b_x - 1))
859 1.1 mrg dirmask |= WEST, count++;
860 1.1 mrg if (!iswall(bp->b_y - 1, bp->b_x))
861 1.1 mrg dirmask |= NORTH, count++;
862 1.1 mrg if (!iswall(bp->b_y + 1, bp->b_x))
863 1.1 mrg dirmask |= SOUTH, count++;
864 1.1 mrg if (dirmask == 0)
865 1.1 mrg if (!iswall(bp->b_y, bp->b_x + 1))
866 1.1 mrg dirmask |= EAST, count++;
867 1.1 mrg break;
868 1.1 mrg case RIGHT:
869 1.1 mrg if (!iswall(bp->b_y, bp->b_x + 1))
870 1.1 mrg dirmask |= EAST, count++;
871 1.1 mrg if (!iswall(bp->b_y - 1, bp->b_x))
872 1.1 mrg dirmask |= NORTH, count++;
873 1.1 mrg if (!iswall(bp->b_y + 1, bp->b_x))
874 1.1 mrg dirmask |= SOUTH, count++;
875 1.1 mrg if (dirmask == 0)
876 1.1 mrg if (!iswall(bp->b_y, bp->b_x - 1))
877 1.1 mrg dirmask |= WEST, count++;
878 1.1 mrg break;
879 1.1 mrg case ABOVE:
880 1.1 mrg if (!iswall(bp->b_y - 1, bp->b_x))
881 1.1 mrg dirmask |= NORTH, count++;
882 1.1 mrg if (!iswall(bp->b_y, bp->b_x - 1))
883 1.1 mrg dirmask |= WEST, count++;
884 1.1 mrg if (!iswall(bp->b_y, bp->b_x + 1))
885 1.1 mrg dirmask |= EAST, count++;
886 1.1 mrg if (dirmask == 0)
887 1.1 mrg if (!iswall(bp->b_y + 1, bp->b_x))
888 1.1 mrg dirmask |= SOUTH, count++;
889 1.1 mrg break;
890 1.1 mrg case BELOW:
891 1.1 mrg if (!iswall(bp->b_y + 1, bp->b_x))
892 1.1 mrg dirmask |= SOUTH, count++;
893 1.1 mrg if (!iswall(bp->b_y, bp->b_x - 1))
894 1.1 mrg dirmask |= WEST, count++;
895 1.1 mrg if (!iswall(bp->b_y, bp->b_x + 1))
896 1.1 mrg dirmask |= EAST, count++;
897 1.1 mrg if (dirmask == 0)
898 1.1 mrg if (!iswall(bp->b_y - 1, bp->b_x))
899 1.1 mrg dirmask |= NORTH, count++;
900 1.1 mrg break;
901 1.1 mrg }
902 1.1 mrg if (count == 0) {
903 1.1 mrg /*
904 1.1 mrg * No place to go. Just sit here for a while and wait
905 1.1 mrg * for adjacent squares to clear out.
906 1.1 mrg */
907 1.1 mrg save_bullet(bp);
908 1.1 mrg return;
909 1.1 mrg }
910 1.1 mrg if (bp->b_charge < count) {
911 1.1 mrg /* Only bp->b_charge paths may be taken */
912 1.1 mrg while (count > bp->b_charge) {
913 1.1 mrg if (dirmask & WEST)
914 1.1 mrg dirmask &= ~WEST;
915 1.1 mrg else if (dirmask & EAST)
916 1.1 mrg dirmask &= ~EAST;
917 1.1 mrg else if (dirmask & NORTH)
918 1.1 mrg dirmask &= ~NORTH;
919 1.1 mrg else if (dirmask & SOUTH)
920 1.1 mrg dirmask &= ~SOUTH;
921 1.1 mrg count--;
922 1.1 mrg }
923 1.1 mrg }
924 1.1 mrg
925 1.1 mrg i = bp->b_charge / count;
926 1.1 mrg j = bp->b_charge % count;
927 1.1 mrg if (dirmask & WEST) {
928 1.1 mrg count--;
929 1.1 mrg nbp = create_shot(bp->b_type, bp->b_y, bp->b_x - 1, LEFTS,
930 1.1 mrg i, bp->b_size, bp->b_owner, bp->b_score, TRUE, SPACE);
931 1.1 mrg move_slime(nbp, speed - 1, next);
932 1.1 mrg }
933 1.1 mrg if (dirmask & EAST) {
934 1.1 mrg count--;
935 1.1 mrg nbp = create_shot(bp->b_type, bp->b_y, bp->b_x + 1, RIGHT,
936 1.1 mrg (count < j) ? i + 1 : i, bp->b_size, bp->b_owner,
937 1.1 mrg bp->b_score, TRUE, SPACE);
938 1.1 mrg move_slime(nbp, speed - 1, next);
939 1.1 mrg }
940 1.1 mrg if (dirmask & NORTH) {
941 1.1 mrg count--;
942 1.1 mrg nbp = create_shot(bp->b_type, bp->b_y - 1, bp->b_x, ABOVE,
943 1.1 mrg (count < j) ? i + 1 : i, bp->b_size, bp->b_owner,
944 1.1 mrg bp->b_score, TRUE, SPACE);
945 1.1 mrg move_slime(nbp, speed - 1, next);
946 1.1 mrg }
947 1.1 mrg if (dirmask & SOUTH) {
948 1.1 mrg count--;
949 1.1 mrg nbp = create_shot(bp->b_type, bp->b_y + 1, bp->b_x, BELOW,
950 1.1 mrg (count < j) ? i + 1 : i, bp->b_size, bp->b_owner,
951 1.1 mrg bp->b_score, TRUE, SPACE);
952 1.1 mrg move_slime(nbp, speed - 1, next);
953 1.1 mrg }
954 1.1 mrg
955 1.1 mrg free((char *) bp);
956 1.1 mrg }
957 1.1 mrg
958 1.1 mrg /*
959 1.1 mrg * iswall:
960 1.1 mrg * returns whether the given location is a wall
961 1.1 mrg */
962 1.2 lukem static int
963 1.1 mrg iswall(y, x)
964 1.2 lukem int y, x;
965 1.1 mrg {
966 1.1 mrg if (y < 0 || x < 0 || y >= HEIGHT || x >= WIDTH)
967 1.1 mrg return TRUE;
968 1.1 mrg switch (Maze[y][x]) {
969 1.1 mrg case WALL1:
970 1.1 mrg case WALL2:
971 1.1 mrg case WALL3:
972 1.1 mrg # ifdef REFLECT
973 1.1 mrg case WALL4:
974 1.1 mrg case WALL5:
975 1.1 mrg # endif
976 1.1 mrg # ifdef RANDOM
977 1.1 mrg case DOOR:
978 1.1 mrg # endif
979 1.1 mrg # ifdef OOZE
980 1.1 mrg case SLIME:
981 1.1 mrg # ifdef VOLCANO
982 1.1 mrg case LAVA:
983 1.1 mrg # endif
984 1.1 mrg # endif
985 1.1 mrg return TRUE;
986 1.1 mrg }
987 1.1 mrg return FALSE;
988 1.1 mrg }
989 1.1 mrg # endif
990 1.1 mrg
991 1.1 mrg /*
992 1.1 mrg * zapshot:
993 1.1 mrg * Take a shot out of the air.
994 1.1 mrg */
995 1.2 lukem static void
996 1.1 mrg zapshot(blist, obp)
997 1.2 lukem BULLET *blist, *obp;
998 1.1 mrg {
999 1.2 lukem BULLET *bp;
1000 1.2 lukem FLAG explode;
1001 1.1 mrg
1002 1.1 mrg explode = FALSE;
1003 1.1 mrg for (bp = blist; bp != NULL; bp = bp->b_next) {
1004 1.1 mrg if (bp->b_x != obp->b_x || bp->b_y != obp->b_y)
1005 1.1 mrg continue;
1006 1.1 mrg if (bp->b_face == obp->b_face)
1007 1.1 mrg continue;
1008 1.1 mrg explode = TRUE;
1009 1.1 mrg break;
1010 1.1 mrg }
1011 1.1 mrg if (!explode)
1012 1.1 mrg return;
1013 1.1 mrg explshot(blist, obp->b_y, obp->b_x);
1014 1.1 mrg }
1015 1.1 mrg
1016 1.1 mrg /*
1017 1.1 mrg * explshot -
1018 1.1 mrg * Make all shots at this location blow up
1019 1.1 mrg */
1020 1.2 lukem void
1021 1.1 mrg explshot(blist, y, x)
1022 1.2 lukem BULLET *blist;
1023 1.2 lukem int y, x;
1024 1.1 mrg {
1025 1.2 lukem BULLET *bp;
1026 1.1 mrg
1027 1.1 mrg for (bp = blist; bp != NULL; bp = bp->b_next)
1028 1.1 mrg if (bp->b_x == x && bp->b_y == y) {
1029 1.1 mrg bp->b_expl = TRUE;
1030 1.1 mrg if (bp->b_owner != NULL)
1031 1.1 mrg message(bp->b_owner, "Shot intercepted");
1032 1.1 mrg }
1033 1.1 mrg }
1034 1.1 mrg
1035 1.1 mrg /*
1036 1.1 mrg * play_at:
1037 1.1 mrg * Return a pointer to the player at the given location
1038 1.1 mrg */
1039 1.1 mrg PLAYER *
1040 1.1 mrg play_at(y, x)
1041 1.2 lukem int y, x;
1042 1.1 mrg {
1043 1.2 lukem PLAYER *pp;
1044 1.1 mrg
1045 1.1 mrg for (pp = Player; pp < End_player; pp++)
1046 1.1 mrg if (pp->p_x == x && pp->p_y == y)
1047 1.1 mrg return pp;
1048 1.3 lukem errx(1, "driver: couldn't find player at (%d,%d)", x, y);
1049 1.1 mrg /* NOTREACHED */
1050 1.1 mrg }
1051 1.1 mrg
1052 1.1 mrg /*
1053 1.1 mrg * opposite:
1054 1.1 mrg * Return TRUE if the bullet direction faces the opposite direction
1055 1.1 mrg * of the player in the maze
1056 1.1 mrg */
1057 1.2 lukem int
1058 1.1 mrg opposite(face, dir)
1059 1.2 lukem int face;
1060 1.2 lukem char dir;
1061 1.1 mrg {
1062 1.1 mrg switch (face) {
1063 1.1 mrg case LEFTS:
1064 1.1 mrg return (dir == RIGHT);
1065 1.1 mrg case RIGHT:
1066 1.1 mrg return (dir == LEFTS);
1067 1.1 mrg case ABOVE:
1068 1.1 mrg return (dir == BELOW);
1069 1.1 mrg case BELOW:
1070 1.1 mrg return (dir == ABOVE);
1071 1.1 mrg default:
1072 1.1 mrg return FALSE;
1073 1.1 mrg }
1074 1.1 mrg }
1075 1.1 mrg
1076 1.1 mrg /*
1077 1.1 mrg * is_bullet:
1078 1.1 mrg * Is there a bullet at the given coordinates? If so, return
1079 1.1 mrg * a pointer to the bullet, otherwise return NULL
1080 1.1 mrg */
1081 1.1 mrg BULLET *
1082 1.1 mrg is_bullet(y, x)
1083 1.2 lukem int y, x;
1084 1.1 mrg {
1085 1.2 lukem BULLET *bp;
1086 1.1 mrg
1087 1.1 mrg for (bp = Bullets; bp != NULL; bp = bp->b_next)
1088 1.1 mrg if (bp->b_y == y && bp->b_x == x)
1089 1.1 mrg return bp;
1090 1.1 mrg return NULL;
1091 1.1 mrg }
1092 1.1 mrg
1093 1.1 mrg /*
1094 1.1 mrg * fixshots:
1095 1.1 mrg * change the underlying character of the shots at a location
1096 1.1 mrg * to the given character.
1097 1.1 mrg */
1098 1.2 lukem void
1099 1.1 mrg fixshots(y, x, over)
1100 1.2 lukem int y, x;
1101 1.2 lukem char over;
1102 1.1 mrg {
1103 1.2 lukem BULLET *bp;
1104 1.1 mrg
1105 1.1 mrg for (bp = Bullets; bp != NULL; bp = bp->b_next)
1106 1.1 mrg if (bp->b_y == y && bp->b_x == x)
1107 1.1 mrg bp->b_over = over;
1108 1.1 mrg }
1109 1.1 mrg
1110 1.1 mrg /*
1111 1.1 mrg * find_under:
1112 1.1 mrg * find the underlying character for a bullet when it lands
1113 1.1 mrg * on another bullet.
1114 1.1 mrg */
1115 1.2 lukem static void
1116 1.1 mrg find_under(blist, bp)
1117 1.2 lukem BULLET *blist, *bp;
1118 1.1 mrg {
1119 1.2 lukem BULLET *nbp;
1120 1.1 mrg
1121 1.1 mrg for (nbp = blist; nbp != NULL; nbp = nbp->b_next)
1122 1.1 mrg if (bp->b_y == nbp->b_y && bp->b_x == nbp->b_x) {
1123 1.1 mrg bp->b_over = nbp->b_over;
1124 1.1 mrg break;
1125 1.1 mrg }
1126 1.1 mrg }
1127 1.1 mrg
1128 1.1 mrg /*
1129 1.1 mrg * mark_player:
1130 1.1 mrg * mark a player as under a shot
1131 1.1 mrg */
1132 1.2 lukem static void
1133 1.1 mrg mark_player(bp)
1134 1.2 lukem BULLET *bp;
1135 1.1 mrg {
1136 1.2 lukem PLAYER *pp;
1137 1.1 mrg
1138 1.1 mrg for (pp = Player; pp < End_player; pp++)
1139 1.1 mrg if (pp->p_y == bp->b_y && pp->p_x == bp->b_x) {
1140 1.1 mrg pp->p_undershot = TRUE;
1141 1.1 mrg break;
1142 1.1 mrg }
1143 1.1 mrg }
1144 1.1 mrg
1145 1.1 mrg # ifdef BOOTS
1146 1.1 mrg /*
1147 1.1 mrg * mark_boot:
1148 1.1 mrg * mark a boot as under a shot
1149 1.1 mrg */
1150 1.2 lukem static void
1151 1.1 mrg mark_boot(bp)
1152 1.2 lukem BULLET *bp;
1153 1.1 mrg {
1154 1.2 lukem PLAYER *pp;
1155 1.1 mrg
1156 1.1 mrg for (pp = Boot; pp < &Boot[NBOOTS]; pp++)
1157 1.1 mrg if (pp->p_y == bp->b_y && pp->p_x == bp->b_x) {
1158 1.1 mrg pp->p_undershot = TRUE;
1159 1.1 mrg break;
1160 1.1 mrg }
1161 1.1 mrg }
1162 1.1 mrg # endif
1163