shots.c revision 1.5 1 1.5 jsm /* $NetBSD: shots.c,v 1.5 2004/01/27 20:30:29 jsm 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.5 jsm __RCSID("$NetBSD: shots.c,v 1.5 2004/01/27 20:30:29 jsm 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.1 mrg (void) sprintf(Buf, "%3d", pp->p_ammo);
320 1.1 mrg cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
321 1.1 mrg outstr(pp, Buf, 3);
322 1.1 mrg return FALSE;
323 1.1 mrg }
324 1.1 mrg pp->p_ident->i_faced += bp->b_charge;
325 1.1 mrg }
326 1.1 mrg /*
327 1.1 mrg * Small chance that the bullet just misses the
328 1.1 mrg * person. If so, the bullet just goes on its
329 1.1 mrg * merry way without exploding.
330 1.1 mrg */
331 1.1 mrg if (rand_num(100) < 5) {
332 1.1 mrg pp->p_ident->i_ducked += bp->b_charge;
333 1.1 mrg if (pp->p_damage + bp->b_size * MINDAM
334 1.1 mrg > pp->p_damcap)
335 1.1 mrg pp->p_ident->i_saved++;
336 1.1 mrg if (bp->b_score != NULL)
337 1.1 mrg bp->b_score->i_missed += bp->b_charge;
338 1.1 mrg message(pp, "Zing!");
339 1.1 mrg if (bp->b_owner == NULL)
340 1.1 mrg break;
341 1.1 mrg message(bp->b_owner,
342 1.1 mrg ((bp->b_score->i_missed & 0x7) == 0x7) ?
343 1.1 mrg "My! What a bad shot you are!" :
344 1.1 mrg "Missed him");
345 1.1 mrg break;
346 1.1 mrg }
347 1.1 mrg /*
348 1.1 mrg * The shot hit that sucker! Blow it up.
349 1.1 mrg */
350 1.1 mrg /* FALLTHROUGH */
351 1.1 mrg # ifndef RANDOM
352 1.1 mrg case DOOR:
353 1.1 mrg # endif
354 1.1 mrg case WALL1:
355 1.1 mrg case WALL2:
356 1.1 mrg case WALL3:
357 1.1 mrg bp->b_expl = TRUE;
358 1.1 mrg break;
359 1.1 mrg }
360 1.1 mrg
361 1.1 mrg bp->b_x = x;
362 1.1 mrg bp->b_y = y;
363 1.1 mrg }
364 1.1 mrg return TRUE;
365 1.1 mrg }
366 1.1 mrg
367 1.1 mrg # ifdef DRONE
368 1.1 mrg /*
369 1.1 mrg * move_drone:
370 1.1 mrg * Move the drone to the next square
371 1.1 mrg */
372 1.2 lukem static void
373 1.1 mrg move_drone(bp)
374 1.2 lukem BULLET *bp;
375 1.1 mrg {
376 1.2 lukem int mask, count;
377 1.2 lukem int n, dir;
378 1.2 lukem PLAYER *pp;
379 1.1 mrg
380 1.1 mrg /*
381 1.1 mrg * See if we can give someone a blast
382 1.1 mrg */
383 1.1 mrg if (isplayer(Maze[bp->b_y][bp->b_x - 1])) {
384 1.1 mrg dir = WEST;
385 1.1 mrg goto drone_move;
386 1.1 mrg }
387 1.1 mrg if (isplayer(Maze[bp->b_y - 1][bp->b_x])) {
388 1.1 mrg dir = NORTH;
389 1.1 mrg goto drone_move;
390 1.1 mrg }
391 1.1 mrg if (isplayer(Maze[bp->b_y + 1][bp->b_x])) {
392 1.1 mrg dir = SOUTH;
393 1.1 mrg goto drone_move;
394 1.1 mrg }
395 1.1 mrg if (isplayer(Maze[bp->b_y][bp->b_x + 1])) {
396 1.1 mrg dir = EAST;
397 1.1 mrg goto drone_move;
398 1.1 mrg }
399 1.1 mrg
400 1.1 mrg /*
401 1.1 mrg * Find out what directions are clear
402 1.1 mrg */
403 1.1 mrg mask = count = 0;
404 1.1 mrg if (!iswall(bp->b_y, bp->b_x - 1))
405 1.1 mrg mask |= WEST, count++;
406 1.1 mrg if (!iswall(bp->b_y - 1, bp->b_x))
407 1.1 mrg mask |= NORTH, count++;
408 1.1 mrg if (!iswall(bp->b_y + 1, bp->b_x))
409 1.1 mrg mask |= SOUTH, count++;
410 1.1 mrg if (!iswall(bp->b_y, bp->b_x + 1))
411 1.1 mrg mask |= EAST, count++;
412 1.1 mrg
413 1.1 mrg /*
414 1.1 mrg * All blocked up, just you wait
415 1.1 mrg */
416 1.1 mrg if (count == 0)
417 1.1 mrg return TRUE;
418 1.1 mrg
419 1.1 mrg /*
420 1.1 mrg * Only one way to go.
421 1.1 mrg */
422 1.1 mrg if (count == 1) {
423 1.1 mrg dir = mask;
424 1.1 mrg goto drone_move;
425 1.1 mrg }
426 1.1 mrg
427 1.1 mrg /*
428 1.1 mrg * Get rid of the direction that we came from
429 1.1 mrg */
430 1.1 mrg switch (bp->b_face) {
431 1.1 mrg case LEFTS:
432 1.1 mrg if (mask & EAST)
433 1.1 mrg mask &= ~EAST, count--;
434 1.1 mrg break;
435 1.1 mrg case RIGHT:
436 1.1 mrg if (mask & WEST)
437 1.1 mrg mask &= ~WEST, count--;
438 1.1 mrg break;
439 1.1 mrg case ABOVE:
440 1.1 mrg if (mask & SOUTH)
441 1.1 mrg mask &= ~SOUTH, count--;
442 1.1 mrg break;
443 1.1 mrg case BELOW:
444 1.1 mrg if (mask & NORTH)
445 1.1 mrg mask &= ~NORTH, count--;
446 1.1 mrg break;
447 1.1 mrg }
448 1.1 mrg
449 1.1 mrg /*
450 1.1 mrg * Pick one of the remaining directions
451 1.1 mrg */
452 1.1 mrg n = rand_num(count);
453 1.1 mrg if (n >= 0 && mask & NORTH)
454 1.1 mrg dir = NORTH, n--;
455 1.1 mrg if (n >= 0 && mask & SOUTH)
456 1.1 mrg dir = SOUTH, n--;
457 1.1 mrg if (n >= 0 && mask & EAST)
458 1.1 mrg dir = EAST, n--;
459 1.1 mrg if (n >= 0 && mask & WEST)
460 1.1 mrg dir = WEST, n--;
461 1.1 mrg
462 1.1 mrg /*
463 1.1 mrg * Now that we know the direction of movement,
464 1.1 mrg * just update the position of the drone
465 1.1 mrg */
466 1.1 mrg drone_move:
467 1.1 mrg switch (dir) {
468 1.1 mrg case WEST:
469 1.1 mrg bp->b_x--;
470 1.1 mrg bp->b_face = LEFTS;
471 1.1 mrg break;
472 1.1 mrg case EAST:
473 1.1 mrg bp->b_x++;
474 1.1 mrg bp->b_face = RIGHT;
475 1.1 mrg break;
476 1.1 mrg case NORTH:
477 1.1 mrg bp->b_y--;
478 1.1 mrg bp->b_face = ABOVE;
479 1.1 mrg break;
480 1.1 mrg case SOUTH:
481 1.1 mrg bp->b_y++;
482 1.1 mrg bp->b_face = BELOW;
483 1.1 mrg break;
484 1.1 mrg }
485 1.1 mrg switch (Maze[bp->b_y][bp->b_x]) {
486 1.1 mrg case LEFTS:
487 1.1 mrg case RIGHT:
488 1.1 mrg case BELOW:
489 1.1 mrg case ABOVE:
490 1.1 mrg /*
491 1.1 mrg * give the person a chance to catch a
492 1.1 mrg * drone if s/he is facing it
493 1.1 mrg */
494 1.1 mrg if (rand_num(100) < 1 &&
495 1.1 mrg opposite(bp->b_face, Maze[bp->b_y][bp->b_x])) {
496 1.1 mrg pp = play_at(bp->b_y, bp->b_x);
497 1.1 mrg pp->p_ammo += bp->b_charge;
498 1.1 mrg message(pp, "**** Absorbed drone ****");
499 1.1 mrg free((char *) bp);
500 1.1 mrg (void) sprintf(Buf, "%3d", pp->p_ammo);
501 1.1 mrg cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
502 1.1 mrg outstr(pp, Buf, 3);
503 1.1 mrg return FALSE;
504 1.1 mrg }
505 1.1 mrg bp->b_expl = TRUE;
506 1.1 mrg break;
507 1.1 mrg }
508 1.1 mrg return TRUE;
509 1.1 mrg }
510 1.1 mrg # endif
511 1.1 mrg
512 1.1 mrg /*
513 1.1 mrg * save_bullet:
514 1.1 mrg * Put this bullet back onto the bullet list
515 1.1 mrg */
516 1.2 lukem static void
517 1.1 mrg save_bullet(bp)
518 1.2 lukem BULLET *bp;
519 1.1 mrg {
520 1.1 mrg bp->b_over = Maze[bp->b_y][bp->b_x];
521 1.1 mrg switch (bp->b_over) {
522 1.1 mrg case SHOT:
523 1.1 mrg case GRENADE:
524 1.1 mrg case SATCHEL:
525 1.1 mrg case BOMB:
526 1.1 mrg # ifdef OOZE
527 1.1 mrg case SLIME:
528 1.1 mrg # ifdef VOLCANO
529 1.1 mrg case LAVA:
530 1.1 mrg # endif
531 1.1 mrg # endif
532 1.1 mrg # ifdef DRONE
533 1.1 mrg case DSHOT:
534 1.1 mrg # endif
535 1.1 mrg find_under(Bullets, bp);
536 1.1 mrg break;
537 1.1 mrg }
538 1.1 mrg
539 1.1 mrg switch (bp->b_over) {
540 1.1 mrg case LEFTS:
541 1.1 mrg case RIGHT:
542 1.1 mrg case ABOVE:
543 1.1 mrg case BELOW:
544 1.1 mrg # ifdef FLY
545 1.1 mrg case FLYER:
546 1.1 mrg # endif
547 1.1 mrg mark_player(bp);
548 1.1 mrg break;
549 1.1 mrg # ifdef BOOTS
550 1.1 mrg case BOOT:
551 1.1 mrg case BOOT_PAIR:
552 1.1 mrg mark_boot(bp);
553 1.1 mrg # endif
554 1.1 mrg
555 1.1 mrg default:
556 1.1 mrg Maze[bp->b_y][bp->b_x] = bp->b_type;
557 1.1 mrg break;
558 1.1 mrg }
559 1.1 mrg
560 1.1 mrg bp->b_next = Bullets;
561 1.1 mrg Bullets = bp;
562 1.1 mrg }
563 1.1 mrg
564 1.1 mrg /*
565 1.1 mrg * move_flyer:
566 1.1 mrg * Update the position of a player in flight
567 1.1 mrg */
568 1.2 lukem static void
569 1.1 mrg move_flyer(pp)
570 1.2 lukem PLAYER *pp;
571 1.1 mrg {
572 1.2 lukem int x, y;
573 1.1 mrg
574 1.1 mrg if (pp->p_undershot) {
575 1.1 mrg fixshots(pp->p_y, pp->p_x, pp->p_over);
576 1.1 mrg pp->p_undershot = FALSE;
577 1.1 mrg }
578 1.1 mrg Maze[pp->p_y][pp->p_x] = pp->p_over;
579 1.1 mrg x = pp->p_x + pp->p_flyx;
580 1.1 mrg y = pp->p_y + pp->p_flyy;
581 1.1 mrg if (x < 1) {
582 1.1 mrg x = 1 - x;
583 1.1 mrg pp->p_flyx = -pp->p_flyx;
584 1.1 mrg }
585 1.1 mrg else if (x > WIDTH - 2) {
586 1.1 mrg x = (WIDTH - 2) - (x - (WIDTH - 2));
587 1.1 mrg pp->p_flyx = -pp->p_flyx;
588 1.1 mrg }
589 1.1 mrg if (y < 1) {
590 1.1 mrg y = 1 - y;
591 1.1 mrg pp->p_flyy = -pp->p_flyy;
592 1.1 mrg }
593 1.1 mrg else if (y > HEIGHT - 2) {
594 1.1 mrg y = (HEIGHT - 2) - (y - (HEIGHT - 2));
595 1.1 mrg pp->p_flyy = -pp->p_flyy;
596 1.1 mrg }
597 1.1 mrg again:
598 1.1 mrg switch (Maze[y][x]) {
599 1.1 mrg default:
600 1.1 mrg switch (rand_num(4)) {
601 1.1 mrg case 0:
602 1.1 mrg PLUS_DELTA(x, WIDTH - 2);
603 1.1 mrg break;
604 1.1 mrg case 1:
605 1.1 mrg MINUS_DELTA(x, 1);
606 1.1 mrg break;
607 1.1 mrg case 2:
608 1.1 mrg PLUS_DELTA(y, HEIGHT - 2);
609 1.1 mrg break;
610 1.1 mrg case 3:
611 1.1 mrg MINUS_DELTA(y, 1);
612 1.1 mrg break;
613 1.1 mrg }
614 1.1 mrg goto again;
615 1.1 mrg case WALL1:
616 1.1 mrg case WALL2:
617 1.1 mrg case WALL3:
618 1.1 mrg # ifdef REFLECT
619 1.1 mrg case WALL4:
620 1.1 mrg case WALL5:
621 1.1 mrg # endif
622 1.1 mrg # ifdef RANDOM
623 1.1 mrg case DOOR:
624 1.1 mrg # endif
625 1.1 mrg if (pp->p_flying == 0)
626 1.1 mrg pp->p_flying++;
627 1.1 mrg break;
628 1.1 mrg case SPACE:
629 1.1 mrg break;
630 1.1 mrg }
631 1.1 mrg pp->p_y = y;
632 1.1 mrg pp->p_x = x;
633 1.1 mrg if (pp->p_flying-- == 0) {
634 1.1 mrg # ifdef BOOTS
635 1.1 mrg if (pp->p_face != BOOT && pp->p_face != BOOT_PAIR) {
636 1.1 mrg # endif
637 1.1 mrg checkdam(pp, (PLAYER *) NULL, (IDENT *) NULL,
638 1.1 mrg rand_num(pp->p_damage / 5), FALL);
639 1.1 mrg pp->p_face = rand_dir();
640 1.1 mrg showstat(pp);
641 1.1 mrg # ifdef BOOTS
642 1.1 mrg }
643 1.1 mrg else {
644 1.1 mrg if (Maze[y][x] == BOOT)
645 1.1 mrg pp->p_face = BOOT_PAIR;
646 1.1 mrg Maze[y][x] = SPACE;
647 1.1 mrg }
648 1.1 mrg # endif
649 1.1 mrg }
650 1.1 mrg pp->p_over = Maze[y][x];
651 1.1 mrg Maze[y][x] = pp->p_face;
652 1.1 mrg showexpl(y, x, pp->p_face);
653 1.1 mrg }
654 1.1 mrg
655 1.1 mrg /*
656 1.1 mrg * chkshot
657 1.1 mrg * Handle explosions
658 1.1 mrg */
659 1.2 lukem static void
660 1.1 mrg chkshot(bp, next)
661 1.2 lukem BULLET *bp;
662 1.2 lukem BULLET *next;
663 1.1 mrg {
664 1.2 lukem int y, x;
665 1.2 lukem int dy, dx, absdy;
666 1.2 lukem int delta, damage;
667 1.2 lukem char expl;
668 1.2 lukem PLAYER *pp;
669 1.1 mrg
670 1.2 lukem delta = 0;
671 1.1 mrg switch (bp->b_type) {
672 1.1 mrg case SHOT:
673 1.1 mrg case MINE:
674 1.1 mrg case GRENADE:
675 1.1 mrg case GMINE:
676 1.1 mrg case SATCHEL:
677 1.1 mrg case BOMB:
678 1.1 mrg delta = bp->b_size - 1;
679 1.1 mrg break;
680 1.1 mrg # ifdef OOZE
681 1.1 mrg case SLIME:
682 1.1 mrg # ifdef VOLCANO
683 1.1 mrg case LAVA:
684 1.1 mrg # endif
685 1.1 mrg chkslime(bp, next);
686 1.1 mrg return;
687 1.1 mrg # endif
688 1.1 mrg # ifdef DRONE
689 1.1 mrg case DSHOT:
690 1.1 mrg bp->b_type = SLIME;
691 1.1 mrg chkslime(bp, next);
692 1.1 mrg return;
693 1.1 mrg # endif
694 1.1 mrg }
695 1.1 mrg for (y = bp->b_y - delta; y <= bp->b_y + delta; y++) {
696 1.1 mrg if (y < 0 || y >= HEIGHT)
697 1.1 mrg continue;
698 1.1 mrg dy = y - bp->b_y;
699 1.1 mrg absdy = (dy < 0) ? -dy : dy;
700 1.1 mrg for (x = bp->b_x - delta; x <= bp->b_x + delta; x++) {
701 1.1 mrg if (x < 0 || x >= WIDTH)
702 1.1 mrg continue;
703 1.1 mrg dx = x - bp->b_x;
704 1.1 mrg if (dx == 0)
705 1.1 mrg expl = (dy == 0) ? '*' : '|';
706 1.1 mrg else if (dy == 0)
707 1.1 mrg expl = '-';
708 1.1 mrg else if (dx == dy)
709 1.1 mrg expl = '\\';
710 1.1 mrg else if (dx == -dy)
711 1.1 mrg expl = '/';
712 1.1 mrg else
713 1.1 mrg expl = '*';
714 1.1 mrg showexpl(y, x, expl);
715 1.1 mrg switch (Maze[y][x]) {
716 1.1 mrg case LEFTS:
717 1.1 mrg case RIGHT:
718 1.1 mrg case ABOVE:
719 1.1 mrg case BELOW:
720 1.1 mrg # ifdef FLY
721 1.1 mrg case FLYER:
722 1.1 mrg # endif
723 1.1 mrg if (dx < 0)
724 1.1 mrg dx = -dx;
725 1.1 mrg if (absdy > dx)
726 1.1 mrg damage = bp->b_size - absdy;
727 1.1 mrg else
728 1.1 mrg damage = bp->b_size - dx;
729 1.1 mrg pp = play_at(y, x);
730 1.1 mrg checkdam(pp, bp->b_owner, bp->b_score,
731 1.1 mrg damage * MINDAM, bp->b_type);
732 1.1 mrg break;
733 1.1 mrg case GMINE:
734 1.1 mrg case MINE:
735 1.1 mrg add_shot((Maze[y][x] == GMINE) ?
736 1.1 mrg GRENADE : SHOT,
737 1.1 mrg y, x, LEFTS,
738 1.1 mrg (Maze[y][x] == GMINE) ?
739 1.1 mrg GRENREQ : BULREQ,
740 1.1 mrg (PLAYER *) NULL, TRUE, SPACE);
741 1.1 mrg Maze[y][x] = SPACE;
742 1.1 mrg break;
743 1.1 mrg }
744 1.1 mrg }
745 1.1 mrg }
746 1.1 mrg }
747 1.1 mrg
748 1.1 mrg # ifdef OOZE
749 1.1 mrg /*
750 1.1 mrg * chkslime:
751 1.1 mrg * handle slime shot exploding
752 1.1 mrg */
753 1.2 lukem static void
754 1.1 mrg chkslime(bp, next)
755 1.2 lukem BULLET *bp;
756 1.2 lukem BULLET *next;
757 1.1 mrg {
758 1.2 lukem BULLET *nbp;
759 1.1 mrg
760 1.1 mrg switch (Maze[bp->b_y][bp->b_x]) {
761 1.1 mrg case WALL1:
762 1.1 mrg case WALL2:
763 1.1 mrg case WALL3:
764 1.1 mrg # ifdef REFLECT
765 1.1 mrg case WALL4:
766 1.1 mrg case WALL5:
767 1.1 mrg # endif
768 1.1 mrg # ifdef RANDOM
769 1.1 mrg case DOOR:
770 1.1 mrg # endif
771 1.1 mrg switch (bp->b_face) {
772 1.1 mrg case LEFTS:
773 1.1 mrg bp->b_x++;
774 1.1 mrg break;
775 1.1 mrg case RIGHT:
776 1.1 mrg bp->b_x--;
777 1.1 mrg break;
778 1.1 mrg case ABOVE:
779 1.1 mrg bp->b_y++;
780 1.1 mrg break;
781 1.1 mrg case BELOW:
782 1.1 mrg bp->b_y--;
783 1.1 mrg break;
784 1.1 mrg }
785 1.1 mrg break;
786 1.1 mrg }
787 1.1 mrg nbp = (BULLET *) malloc(sizeof (BULLET));
788 1.1 mrg *nbp = *bp;
789 1.1 mrg # ifdef VOLCANO
790 1.1 mrg move_slime(nbp, nbp->b_type == SLIME ? SLIMESPEED : LAVASPEED, next);
791 1.1 mrg # else
792 1.1 mrg move_slime(nbp, SLIMESPEED, next);
793 1.1 mrg # endif
794 1.1 mrg }
795 1.1 mrg
796 1.1 mrg /*
797 1.1 mrg * move_slime:
798 1.1 mrg * move the given slime shot speed times and add it back if
799 1.1 mrg * it hasn't fizzled yet
800 1.1 mrg */
801 1.2 lukem void
802 1.1 mrg move_slime(bp, speed, next)
803 1.2 lukem BULLET *bp;
804 1.2 lukem int speed;
805 1.2 lukem BULLET *next;
806 1.1 mrg {
807 1.2 lukem int i, j, dirmask, count;
808 1.2 lukem PLAYER *pp;
809 1.2 lukem BULLET *nbp;
810 1.1 mrg
811 1.1 mrg if (speed == 0) {
812 1.1 mrg if (bp->b_charge <= 0)
813 1.1 mrg free((char *) bp);
814 1.1 mrg else
815 1.1 mrg save_bullet(bp);
816 1.1 mrg return;
817 1.1 mrg }
818 1.1 mrg
819 1.1 mrg # ifdef VOLCANO
820 1.1 mrg showexpl(bp->b_y, bp->b_x, bp->b_type == LAVA ? LAVA : '*');
821 1.1 mrg # else
822 1.1 mrg showexpl(bp->b_y, bp->b_x, '*');
823 1.1 mrg # endif
824 1.1 mrg switch (Maze[bp->b_y][bp->b_x]) {
825 1.1 mrg case LEFTS:
826 1.1 mrg case RIGHT:
827 1.1 mrg case ABOVE:
828 1.1 mrg case BELOW:
829 1.1 mrg # ifdef FLY
830 1.1 mrg case FLYER:
831 1.1 mrg # endif
832 1.1 mrg pp = play_at(bp->b_y, bp->b_x);
833 1.1 mrg message(pp, "You've been slimed.");
834 1.1 mrg checkdam(pp, bp->b_owner, bp->b_score, MINDAM, bp->b_type);
835 1.1 mrg break;
836 1.1 mrg case SHOT:
837 1.1 mrg case GRENADE:
838 1.1 mrg case SATCHEL:
839 1.1 mrg case BOMB:
840 1.1 mrg # ifdef DRONE
841 1.1 mrg case DSHOT:
842 1.1 mrg # endif
843 1.1 mrg explshot(next, bp->b_y, bp->b_x);
844 1.1 mrg explshot(Bullets, bp->b_y, bp->b_x);
845 1.1 mrg break;
846 1.1 mrg }
847 1.1 mrg
848 1.1 mrg if (--bp->b_charge <= 0) {
849 1.1 mrg free((char *) bp);
850 1.1 mrg return;
851 1.1 mrg }
852 1.1 mrg
853 1.1 mrg dirmask = 0;
854 1.1 mrg count = 0;
855 1.1 mrg switch (bp->b_face) {
856 1.1 mrg case LEFTS:
857 1.1 mrg if (!iswall(bp->b_y, bp->b_x - 1))
858 1.1 mrg dirmask |= WEST, count++;
859 1.1 mrg if (!iswall(bp->b_y - 1, bp->b_x))
860 1.1 mrg dirmask |= NORTH, count++;
861 1.1 mrg if (!iswall(bp->b_y + 1, bp->b_x))
862 1.1 mrg dirmask |= SOUTH, count++;
863 1.1 mrg if (dirmask == 0)
864 1.1 mrg if (!iswall(bp->b_y, bp->b_x + 1))
865 1.1 mrg dirmask |= EAST, count++;
866 1.1 mrg break;
867 1.1 mrg case RIGHT:
868 1.1 mrg if (!iswall(bp->b_y, bp->b_x + 1))
869 1.1 mrg dirmask |= EAST, count++;
870 1.1 mrg if (!iswall(bp->b_y - 1, bp->b_x))
871 1.1 mrg dirmask |= NORTH, count++;
872 1.1 mrg if (!iswall(bp->b_y + 1, bp->b_x))
873 1.1 mrg dirmask |= SOUTH, count++;
874 1.1 mrg if (dirmask == 0)
875 1.1 mrg if (!iswall(bp->b_y, bp->b_x - 1))
876 1.1 mrg dirmask |= WEST, count++;
877 1.1 mrg break;
878 1.1 mrg case ABOVE:
879 1.1 mrg if (!iswall(bp->b_y - 1, bp->b_x))
880 1.1 mrg dirmask |= NORTH, count++;
881 1.1 mrg if (!iswall(bp->b_y, bp->b_x - 1))
882 1.1 mrg dirmask |= WEST, count++;
883 1.1 mrg if (!iswall(bp->b_y, bp->b_x + 1))
884 1.1 mrg dirmask |= EAST, count++;
885 1.1 mrg if (dirmask == 0)
886 1.1 mrg if (!iswall(bp->b_y + 1, bp->b_x))
887 1.1 mrg dirmask |= SOUTH, count++;
888 1.1 mrg break;
889 1.1 mrg case BELOW:
890 1.1 mrg if (!iswall(bp->b_y + 1, bp->b_x))
891 1.1 mrg dirmask |= SOUTH, count++;
892 1.1 mrg if (!iswall(bp->b_y, bp->b_x - 1))
893 1.1 mrg dirmask |= WEST, count++;
894 1.1 mrg if (!iswall(bp->b_y, bp->b_x + 1))
895 1.1 mrg dirmask |= EAST, count++;
896 1.1 mrg if (dirmask == 0)
897 1.1 mrg if (!iswall(bp->b_y - 1, bp->b_x))
898 1.1 mrg dirmask |= NORTH, count++;
899 1.1 mrg break;
900 1.1 mrg }
901 1.1 mrg if (count == 0) {
902 1.1 mrg /*
903 1.1 mrg * No place to go. Just sit here for a while and wait
904 1.1 mrg * for adjacent squares to clear out.
905 1.1 mrg */
906 1.1 mrg save_bullet(bp);
907 1.1 mrg return;
908 1.1 mrg }
909 1.1 mrg if (bp->b_charge < count) {
910 1.1 mrg /* Only bp->b_charge paths may be taken */
911 1.1 mrg while (count > bp->b_charge) {
912 1.1 mrg if (dirmask & WEST)
913 1.1 mrg dirmask &= ~WEST;
914 1.1 mrg else if (dirmask & EAST)
915 1.1 mrg dirmask &= ~EAST;
916 1.1 mrg else if (dirmask & NORTH)
917 1.1 mrg dirmask &= ~NORTH;
918 1.1 mrg else if (dirmask & SOUTH)
919 1.1 mrg dirmask &= ~SOUTH;
920 1.1 mrg count--;
921 1.1 mrg }
922 1.1 mrg }
923 1.1 mrg
924 1.1 mrg i = bp->b_charge / count;
925 1.1 mrg j = bp->b_charge % count;
926 1.1 mrg if (dirmask & WEST) {
927 1.1 mrg count--;
928 1.1 mrg nbp = create_shot(bp->b_type, bp->b_y, bp->b_x - 1, LEFTS,
929 1.1 mrg i, bp->b_size, bp->b_owner, bp->b_score, TRUE, SPACE);
930 1.1 mrg move_slime(nbp, speed - 1, next);
931 1.1 mrg }
932 1.1 mrg if (dirmask & EAST) {
933 1.1 mrg count--;
934 1.1 mrg nbp = create_shot(bp->b_type, bp->b_y, bp->b_x + 1, RIGHT,
935 1.1 mrg (count < j) ? i + 1 : i, bp->b_size, bp->b_owner,
936 1.1 mrg bp->b_score, TRUE, SPACE);
937 1.1 mrg move_slime(nbp, speed - 1, next);
938 1.1 mrg }
939 1.1 mrg if (dirmask & NORTH) {
940 1.1 mrg count--;
941 1.1 mrg nbp = create_shot(bp->b_type, bp->b_y - 1, bp->b_x, ABOVE,
942 1.1 mrg (count < j) ? i + 1 : i, bp->b_size, bp->b_owner,
943 1.1 mrg bp->b_score, TRUE, SPACE);
944 1.1 mrg move_slime(nbp, speed - 1, next);
945 1.1 mrg }
946 1.1 mrg if (dirmask & SOUTH) {
947 1.1 mrg count--;
948 1.1 mrg nbp = create_shot(bp->b_type, bp->b_y + 1, bp->b_x, BELOW,
949 1.1 mrg (count < j) ? i + 1 : i, bp->b_size, bp->b_owner,
950 1.1 mrg bp->b_score, TRUE, SPACE);
951 1.1 mrg move_slime(nbp, speed - 1, next);
952 1.1 mrg }
953 1.1 mrg
954 1.1 mrg free((char *) bp);
955 1.1 mrg }
956 1.1 mrg
957 1.1 mrg /*
958 1.1 mrg * iswall:
959 1.1 mrg * returns whether the given location is a wall
960 1.1 mrg */
961 1.2 lukem static int
962 1.1 mrg iswall(y, x)
963 1.2 lukem int y, x;
964 1.1 mrg {
965 1.1 mrg if (y < 0 || x < 0 || y >= HEIGHT || x >= WIDTH)
966 1.1 mrg return TRUE;
967 1.1 mrg switch (Maze[y][x]) {
968 1.1 mrg case WALL1:
969 1.1 mrg case WALL2:
970 1.1 mrg case WALL3:
971 1.1 mrg # ifdef REFLECT
972 1.1 mrg case WALL4:
973 1.1 mrg case WALL5:
974 1.1 mrg # endif
975 1.1 mrg # ifdef RANDOM
976 1.1 mrg case DOOR:
977 1.1 mrg # endif
978 1.1 mrg # ifdef OOZE
979 1.1 mrg case SLIME:
980 1.1 mrg # ifdef VOLCANO
981 1.1 mrg case LAVA:
982 1.1 mrg # endif
983 1.1 mrg # endif
984 1.1 mrg return TRUE;
985 1.1 mrg }
986 1.1 mrg return FALSE;
987 1.1 mrg }
988 1.1 mrg # endif
989 1.1 mrg
990 1.1 mrg /*
991 1.1 mrg * zapshot:
992 1.1 mrg * Take a shot out of the air.
993 1.1 mrg */
994 1.2 lukem static void
995 1.1 mrg zapshot(blist, obp)
996 1.2 lukem BULLET *blist, *obp;
997 1.1 mrg {
998 1.2 lukem BULLET *bp;
999 1.2 lukem FLAG explode;
1000 1.1 mrg
1001 1.1 mrg explode = FALSE;
1002 1.1 mrg for (bp = blist; bp != NULL; bp = bp->b_next) {
1003 1.1 mrg if (bp->b_x != obp->b_x || bp->b_y != obp->b_y)
1004 1.1 mrg continue;
1005 1.1 mrg if (bp->b_face == obp->b_face)
1006 1.1 mrg continue;
1007 1.1 mrg explode = TRUE;
1008 1.1 mrg break;
1009 1.1 mrg }
1010 1.1 mrg if (!explode)
1011 1.1 mrg return;
1012 1.1 mrg explshot(blist, obp->b_y, obp->b_x);
1013 1.1 mrg }
1014 1.1 mrg
1015 1.1 mrg /*
1016 1.1 mrg * explshot -
1017 1.1 mrg * Make all shots at this location blow up
1018 1.1 mrg */
1019 1.2 lukem void
1020 1.1 mrg explshot(blist, y, x)
1021 1.2 lukem BULLET *blist;
1022 1.2 lukem int y, x;
1023 1.1 mrg {
1024 1.2 lukem BULLET *bp;
1025 1.1 mrg
1026 1.1 mrg for (bp = blist; bp != NULL; bp = bp->b_next)
1027 1.1 mrg if (bp->b_x == x && bp->b_y == y) {
1028 1.1 mrg bp->b_expl = TRUE;
1029 1.1 mrg if (bp->b_owner != NULL)
1030 1.1 mrg message(bp->b_owner, "Shot intercepted");
1031 1.1 mrg }
1032 1.1 mrg }
1033 1.1 mrg
1034 1.1 mrg /*
1035 1.1 mrg * play_at:
1036 1.1 mrg * Return a pointer to the player at the given location
1037 1.1 mrg */
1038 1.1 mrg PLAYER *
1039 1.1 mrg play_at(y, x)
1040 1.2 lukem int y, x;
1041 1.1 mrg {
1042 1.2 lukem PLAYER *pp;
1043 1.1 mrg
1044 1.1 mrg for (pp = Player; pp < End_player; pp++)
1045 1.1 mrg if (pp->p_x == x && pp->p_y == y)
1046 1.1 mrg return pp;
1047 1.3 lukem errx(1, "driver: couldn't find player at (%d,%d)", x, y);
1048 1.1 mrg /* NOTREACHED */
1049 1.1 mrg }
1050 1.1 mrg
1051 1.1 mrg /*
1052 1.1 mrg * opposite:
1053 1.1 mrg * Return TRUE if the bullet direction faces the opposite direction
1054 1.1 mrg * of the player in the maze
1055 1.1 mrg */
1056 1.2 lukem int
1057 1.1 mrg opposite(face, dir)
1058 1.2 lukem int face;
1059 1.2 lukem char dir;
1060 1.1 mrg {
1061 1.1 mrg switch (face) {
1062 1.1 mrg case LEFTS:
1063 1.1 mrg return (dir == RIGHT);
1064 1.1 mrg case RIGHT:
1065 1.1 mrg return (dir == LEFTS);
1066 1.1 mrg case ABOVE:
1067 1.1 mrg return (dir == BELOW);
1068 1.1 mrg case BELOW:
1069 1.1 mrg return (dir == ABOVE);
1070 1.1 mrg default:
1071 1.1 mrg return FALSE;
1072 1.1 mrg }
1073 1.1 mrg }
1074 1.1 mrg
1075 1.1 mrg /*
1076 1.1 mrg * is_bullet:
1077 1.1 mrg * Is there a bullet at the given coordinates? If so, return
1078 1.1 mrg * a pointer to the bullet, otherwise return NULL
1079 1.1 mrg */
1080 1.1 mrg BULLET *
1081 1.1 mrg is_bullet(y, x)
1082 1.2 lukem int y, x;
1083 1.1 mrg {
1084 1.2 lukem BULLET *bp;
1085 1.1 mrg
1086 1.1 mrg for (bp = Bullets; bp != NULL; bp = bp->b_next)
1087 1.1 mrg if (bp->b_y == y && bp->b_x == x)
1088 1.1 mrg return bp;
1089 1.1 mrg return NULL;
1090 1.1 mrg }
1091 1.1 mrg
1092 1.1 mrg /*
1093 1.1 mrg * fixshots:
1094 1.1 mrg * change the underlying character of the shots at a location
1095 1.1 mrg * to the given character.
1096 1.1 mrg */
1097 1.2 lukem void
1098 1.1 mrg fixshots(y, x, over)
1099 1.2 lukem int y, x;
1100 1.2 lukem char over;
1101 1.1 mrg {
1102 1.2 lukem BULLET *bp;
1103 1.1 mrg
1104 1.1 mrg for (bp = Bullets; bp != NULL; bp = bp->b_next)
1105 1.1 mrg if (bp->b_y == y && bp->b_x == x)
1106 1.1 mrg bp->b_over = over;
1107 1.1 mrg }
1108 1.1 mrg
1109 1.1 mrg /*
1110 1.1 mrg * find_under:
1111 1.1 mrg * find the underlying character for a bullet when it lands
1112 1.1 mrg * on another bullet.
1113 1.1 mrg */
1114 1.2 lukem static void
1115 1.1 mrg find_under(blist, bp)
1116 1.2 lukem BULLET *blist, *bp;
1117 1.1 mrg {
1118 1.2 lukem BULLET *nbp;
1119 1.1 mrg
1120 1.1 mrg for (nbp = blist; nbp != NULL; nbp = nbp->b_next)
1121 1.1 mrg if (bp->b_y == nbp->b_y && bp->b_x == nbp->b_x) {
1122 1.1 mrg bp->b_over = nbp->b_over;
1123 1.1 mrg break;
1124 1.1 mrg }
1125 1.1 mrg }
1126 1.1 mrg
1127 1.1 mrg /*
1128 1.1 mrg * mark_player:
1129 1.1 mrg * mark a player as under a shot
1130 1.1 mrg */
1131 1.2 lukem static void
1132 1.1 mrg mark_player(bp)
1133 1.2 lukem BULLET *bp;
1134 1.1 mrg {
1135 1.2 lukem PLAYER *pp;
1136 1.1 mrg
1137 1.1 mrg for (pp = Player; pp < End_player; pp++)
1138 1.1 mrg if (pp->p_y == bp->b_y && pp->p_x == bp->b_x) {
1139 1.1 mrg pp->p_undershot = TRUE;
1140 1.1 mrg break;
1141 1.1 mrg }
1142 1.1 mrg }
1143 1.1 mrg
1144 1.1 mrg # ifdef BOOTS
1145 1.1 mrg /*
1146 1.1 mrg * mark_boot:
1147 1.1 mrg * mark a boot as under a shot
1148 1.1 mrg */
1149 1.2 lukem static void
1150 1.1 mrg mark_boot(bp)
1151 1.2 lukem BULLET *bp;
1152 1.1 mrg {
1153 1.2 lukem PLAYER *pp;
1154 1.1 mrg
1155 1.1 mrg for (pp = Boot; pp < &Boot[NBOOTS]; pp++)
1156 1.1 mrg if (pp->p_y == bp->b_y && pp->p_x == bp->b_x) {
1157 1.1 mrg pp->p_undershot = TRUE;
1158 1.1 mrg break;
1159 1.1 mrg }
1160 1.1 mrg }
1161 1.1 mrg # endif
1162