-/* $NetBSD: shots.c,v 1.9 2009/07/04 02:37:20 dholland Exp $ */
+/* $NetBSD: shots.c,v 1.12 2011/08/31 16:24:56 plunky Exp $ */
/*
* Copyright (c) 1983-2003, Regents of the University of California.
* All rights reserved.
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: shots.c,v 1.9 2009/07/04 02:37:20 dholland Exp $");
+__RCSID("$NetBSD: shots.c,v 1.12 2011/08/31 16:24:56 plunky Exp $");
#endif /* not lint */
-# include <err.h>
-# include <signal.h>
-# include <stdlib.h>
-# include "hunt.h"
+#include <err.h>
+#include <signal.h>
+#include <stdlib.h>
+#include "hunt.h"
-# define PLUS_DELTA(x, max) if (x < max) x++; else x--
-# define MINUS_DELTA(x, min) if (x > min) x--; else x++
+#define PLUS_DELTA(x, max) if (x < max) x++; else x--
+#define MINUS_DELTA(x, min) if (x > min) x--; else x++
-static void chkshot(BULLET *, BULLET *);
-static void chkslime(BULLET *, BULLET *);
-static void explshot(BULLET *, int, int);
-static void find_under(BULLET *, BULLET *);
-static int iswall(int, int);
-static void mark_boot(BULLET *);
-static void mark_player(BULLET *);
+static void chkshot(BULLET *, BULLET *);
+static void chkslime(BULLET *, BULLET *);
+static void explshot(BULLET *, int, int);
+static void find_under(BULLET *, BULLET *);
+static int iswall(int, int);
+static void mark_boot(BULLET *);
+static void mark_player(BULLET *);
#ifdef DRONE
-static void move_drone(BULLET *);
+static void move_drone(BULLET *);
#endif
-static void move_flyer(PLAYER *);
-static int move_normal_shot(BULLET *);
-static void move_slime(BULLET *, int, BULLET *);
-static void save_bullet(BULLET *);
-static void zapshot(BULLET *, BULLET *);
+static void move_flyer(PLAYER *);
+static int move_normal_shot(BULLET *);
+static void move_slime(BULLET *, int, BULLET *);
+static void save_bullet(BULLET *);
+static void zapshot(BULLET *, BULLET *);
/*
* moveshots:
void
moveshots(void)
{
- BULLET *bp, *next;
- PLAYER *pp;
- int x, y;
- BULLET *blist;
+ BULLET *bp, *next;
+ PLAYER *pp;
+ int x, y;
+ BULLET *blist;
rollexpl();
if (Bullets == NULL)
Maze[y][x] = bp->b_over;
for (pp = Player; pp < End_player; pp++)
check(pp, y, x);
-# ifdef MONITOR
+#ifdef MONITOR
for (pp = Monitor; pp < End_monitor; pp++)
check(pp, y, x);
-# endif
+#endif
switch (bp->b_type) {
case SHOT:
Bullets = bp;
}
break;
-# ifdef OOZE
+#ifdef OOZE
case SLIME:
if (bp->b_expl || move_normal_shot(bp)) {
bp->b_next = Bullets;
Bullets = bp;
}
break;
-# endif
-# ifdef DRONE
+#endif
+#ifdef DRONE
case DSHOT:
if (move_drone(bp)) {
bp->b_next = Bullets;
Bullets = bp;
}
break;
-# endif
+#endif
default:
bp->b_next = Bullets;
Bullets = bp;
next = bp->b_next;
if (!bp->b_expl) {
save_bullet(bp);
-# ifdef MONITOR
+#ifdef MONITOR
for (pp = Monitor; pp < End_monitor; pp++)
check(pp, bp->b_y, bp->b_x);
-# endif
-# ifdef DRONE
+#endif
+#ifdef DRONE
if (bp->b_type == DSHOT)
for (pp = Player; pp < End_player; pp++)
if (pp->p_scan >= 0)
check(pp, bp->b_y, bp->b_x);
-# endif
+#endif
continue;
}
Maze[pp->p_y][pp->p_x] = pp->p_face;
ret:
-# ifdef BOOTS
+#ifdef BOOTS
for (pp = Boot; pp < &Boot[NBOOTS]; pp++)
if (pp->p_flying >= 0)
move_flyer(pp);
-# endif
+#endif
for (pp = Player; pp < End_player; pp++) {
-# ifdef FLY
+#ifdef FLY
if (pp->p_flying >= 0)
move_flyer(pp);
-# endif
+#endif
sendcom(pp, REFRESH); /* Flush out the explosions */
look(pp);
sendcom(pp, REFRESH);
}
-# ifdef MONITOR
+#ifdef MONITOR
for (pp = Monitor; pp < End_monitor; pp++)
sendcom(pp, REFRESH);
-# endif
+#endif
return;
}
static int
move_normal_shot(BULLET *bp)
{
- int i, x, y;
- PLAYER *pp;
+ int i, x, y;
+ PLAYER *pp;
for (i = 0; i < BULSPD; i++) {
if (bp->b_expl)
zapshot(bp->b_next, bp);
}
break;
-# ifdef REFLECT
+#ifdef REFLECT
case WALL4: /* reflecting walls */
switch (bp->b_face) {
case LEFTS:
break;
}
Maze[y][x] = WALL5;
-# ifdef MONITOR
+#ifdef MONITOR
for (pp = Monitor; pp < End_monitor; pp++)
check(pp, y, x);
-# endif
+#endif
break;
case WALL5:
switch (bp->b_face) {
break;
}
Maze[y][x] = WALL4;
-# ifdef MONITOR
+#ifdef MONITOR
for (pp = Monitor; pp < End_monitor; pp++)
check(pp, y, x);
-# endif
+#endif
break;
-# endif
-# ifdef RANDOM
+#endif
+#ifdef RANDOM
case DOOR:
switch (rand_num(4)) {
case 0:
break;
}
break;
-# endif
-# ifdef FLY
+#endif
+#ifdef FLY
case FLYER:
pp = play_at(y, x);
message(pp, "Zing!");
break;
-# endif
+#endif
case LEFTS:
case RIGHT:
case BELOW:
* The shot hit that sucker! Blow it up.
*/
/* FALLTHROUGH */
-# ifndef RANDOM
+#ifndef RANDOM
case DOOR:
-# endif
+#endif
case WALL1:
case WALL2:
case WALL3:
return TRUE;
}
-# ifdef DRONE
+#ifdef DRONE
/*
* move_drone:
* Move the drone to the next square
static void
move_drone(BULLET *bp)
{
- int mask, count;
- int n, dir;
- PLAYER *pp;
+ int mask, count;
+ int n, dir;
+ PLAYER *pp;
/*
* See if we can give someone a blast
}
return TRUE;
}
-# endif
+#endif
/*
* save_bullet:
case GRENADE:
case SATCHEL:
case BOMB:
-# ifdef OOZE
+#ifdef OOZE
case SLIME:
-# ifdef VOLCANO
+#ifdef VOLCANO
case LAVA:
-# endif
-# endif
-# ifdef DRONE
+#endif
+#endif
+#ifdef DRONE
case DSHOT:
-# endif
+#endif
find_under(Bullets, bp);
break;
}
case RIGHT:
case ABOVE:
case BELOW:
-# ifdef FLY
+#ifdef FLY
case FLYER:
-# endif
+#endif
mark_player(bp);
break;
-# ifdef BOOTS
+#ifdef BOOTS
case BOOT:
case BOOT_PAIR:
mark_boot(bp);
-# endif
-
+#endif
+
default:
Maze[bp->b_y][bp->b_x] = bp->b_type;
break;
static void
move_flyer(PLAYER *pp)
{
- int x, y;
+ int x, y;
if (pp->p_undershot) {
fixshots(pp->p_y, pp->p_x, pp->p_over);
case WALL1:
case WALL2:
case WALL3:
-# ifdef REFLECT
+#ifdef REFLECT
case WALL4:
case WALL5:
-# endif
-# ifdef RANDOM
+#endif
+#ifdef RANDOM
case DOOR:
-# endif
+#endif
if (pp->p_flying == 0)
pp->p_flying++;
break;
pp->p_y = y;
pp->p_x = x;
if (pp->p_flying-- == 0) {
-# ifdef BOOTS
+#ifdef BOOTS
if (pp->p_face != BOOT && pp->p_face != BOOT_PAIR) {
-# endif
- checkdam(pp, (PLAYER *) NULL, (IDENT *) NULL,
+#endif
+ checkdam(pp, NULL, NULL,
rand_num(pp->p_damage / 5), FALL);
pp->p_face = rand_dir();
showstat(pp);
-# ifdef BOOTS
+#ifdef BOOTS
}
else {
if (Maze[y][x] == BOOT)
pp->p_face = BOOT_PAIR;
Maze[y][x] = SPACE;
}
-# endif
+#endif
}
pp->p_over = Maze[y][x];
Maze[y][x] = pp->p_face;
static void
chkshot(BULLET *bp, BULLET *next)
{
- int y, x;
- int dy, dx, absdy;
- int delta, damage;
- char expl;
- PLAYER *pp;
+ int y, x;
+ int dy, dx, absdy;
+ int delta, damage;
+ char expl;
+ PLAYER *pp;
delta = 0;
switch (bp->b_type) {
case BOMB:
delta = bp->b_size - 1;
break;
-# ifdef OOZE
+#ifdef OOZE
case SLIME:
-# ifdef VOLCANO
+#ifdef VOLCANO
case LAVA:
-# endif
+#endif
chkslime(bp, next);
return;
-# endif
-# ifdef DRONE
+#endif
+#ifdef DRONE
case DSHOT:
bp->b_type = SLIME;
chkslime(bp, next);
return;
-# endif
+#endif
}
for (y = bp->b_y - delta; y <= bp->b_y + delta; y++) {
if (y < 0 || y >= HEIGHT)
case RIGHT:
case ABOVE:
case BELOW:
-# ifdef FLY
+#ifdef FLY
case FLYER:
-# endif
+#endif
if (dx < 0)
dx = -dx;
if (absdy > dx)
y, x, LEFTS,
(Maze[y][x] == GMINE) ?
GRENREQ : BULREQ,
- (PLAYER *) NULL, TRUE, SPACE);
+ NULL, TRUE, SPACE);
Maze[y][x] = SPACE;
break;
}
}
}
-# ifdef OOZE
+#ifdef OOZE
/*
* chkslime:
* handle slime shot exploding
case WALL1:
case WALL2:
case WALL3:
-# ifdef REFLECT
+#ifdef REFLECT
case WALL4:
case WALL5:
-# endif
-# ifdef RANDOM
+#endif
+#ifdef RANDOM
case DOOR:
-# endif
+#endif
switch (bp->b_face) {
case LEFTS:
bp->b_x++;
}
nbp = malloc(sizeof(*nbp));
*nbp = *bp;
-# ifdef VOLCANO
+#ifdef VOLCANO
move_slime(nbp, nbp->b_type == SLIME ? SLIMESPEED : LAVASPEED, next);
-# else
+#else
move_slime(nbp, SLIMESPEED, next);
-# endif
+#endif
}
/*
void
move_slime(BULLET *bp, int speed, BULLET *next)
{
- int i, j, dirmask, count;
- PLAYER *pp;
- BULLET *nbp;
+ int i, j, dirmask, count;
+ PLAYER *pp;
+ BULLET *nbp;
if (speed == 0) {
if (bp->b_charge <= 0)
return;
}
-# ifdef VOLCANO
+#ifdef VOLCANO
showexpl(bp->b_y, bp->b_x, bp->b_type == LAVA ? LAVA : '*');
-# else
+#else
showexpl(bp->b_y, bp->b_x, '*');
-# endif
+#endif
switch (Maze[bp->b_y][bp->b_x]) {
case LEFTS:
case RIGHT:
case ABOVE:
case BELOW:
-# ifdef FLY
+#ifdef FLY
case FLYER:
-# endif
+#endif
pp = play_at(bp->b_y, bp->b_x);
message(pp, "You've been slimed.");
checkdam(pp, bp->b_owner, bp->b_score, MINDAM, bp->b_type);
case GRENADE:
case SATCHEL:
case BOMB:
-# ifdef DRONE
+#ifdef DRONE
case DSHOT:
-# endif
+#endif
explshot(next, bp->b_y, bp->b_x);
explshot(Bullets, bp->b_y, bp->b_x);
break;
case WALL1:
case WALL2:
case WALL3:
-# ifdef REFLECT
+#ifdef REFLECT
case WALL4:
case WALL5:
-# endif
-# ifdef RANDOM
+#endif
+#ifdef RANDOM
case DOOR:
-# endif
-# ifdef OOZE
+#endif
+#ifdef OOZE
case SLIME:
-# ifdef VOLCANO
+#ifdef VOLCANO
case LAVA:
-# endif
-# endif
+#endif
+#endif
return TRUE;
}
return FALSE;
}
-# endif
+#endif
/*
* zapshot:
static void
zapshot(BULLET *blist, BULLET *obp)
{
- BULLET *bp;
- FLAG explode;
+ BULLET *bp;
+ FLAG explode;
explode = FALSE;
for (bp = blist; bp != NULL; bp = bp->b_next) {
void
explshot(BULLET *blist, int y, int x)
{
- BULLET *bp;
+ BULLET *bp;
for (bp = blist; bp != NULL; bp = bp->b_next)
if (bp->b_x == x && bp->b_y == y) {
PLAYER *
play_at(int y, int x)
{
- PLAYER *pp;
+ PLAYER *pp;
for (pp = Player; pp < End_player; pp++)
if (pp->p_x == x && pp->p_y == y)
BULLET *
is_bullet(int y, int x)
{
- BULLET *bp;
+ BULLET *bp;
for (bp = Bullets; bp != NULL; bp = bp->b_next)
if (bp->b_y == y && bp->b_x == x)
void
fixshots(int y, int x, char over)
{
- BULLET *bp;
+ BULLET *bp;
for (bp = Bullets; bp != NULL; bp = bp->b_next)
if (bp->b_y == y && bp->b_x == x)
static void
find_under(BULLET *blist, BULLET *bp)
{
- BULLET *nbp;
+ BULLET *nbp;
for (nbp = blist; nbp != NULL; nbp = nbp->b_next)
if (bp->b_y == nbp->b_y && bp->b_x == nbp->b_x) {
static void
mark_player(BULLET *bp)
{
- PLAYER *pp;
+ PLAYER *pp;
for (pp = Player; pp < End_player; pp++)
if (pp->p_y == bp->b_y && pp->p_x == bp->b_x) {
}
}
-# ifdef BOOTS
+#ifdef BOOTS
/*
* mark_boot:
* mark a boot as under a shot
static void
mark_boot(BULLET *bp)
{
- PLAYER *pp;
+ PLAYER *pp;
for (pp = Boot; pp < &Boot[NBOOTS]; pp++)
if (pp->p_y == bp->b_y && pp->p_x == bp->b_x) {
break;
}
}
-# endif
+#endif