+/* $NetBSD: execute.c,v 1.12 2014/03/29 21:38:54 dholland Exp $ */
/*
- * Hunt
- * Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold
- * San Francisco, California
+ * Copyright (c) 1983-2003, Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * + Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * + Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * + Neither the name of the University of California, San Francisco nor
+ * the names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-# include "hunt.h"
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: execute.c,v 1.12 2014/03/29 21:38:54 dholland Exp $");
+#endif /* not lint */
-# ifdef MONITOR
+#include <stdlib.h>
+#include "hunt.h"
+
+static void cloak(PLAYER *);
+static void turn_player(PLAYER *, int);
+static void fire(PLAYER *, int);
+static void fire_slime(PLAYER *, int);
+static void move_player(PLAYER *, int);
+static void pickup(PLAYER *, int, int, int, int);
+static void scan(PLAYER *);
+
+
+#ifdef MONITOR
/*
* mon_execute:
* Execute a single monitor command
*/
-mon_execute(pp)
-register PLAYER *pp;
+void
+mon_execute(PLAYER *pp)
{
- register char ch;
+ char ch;
ch = pp->p_cbuf[pp->p_ncount++];
switch (ch) {
break;
}
}
-# endif
+#endif
/*
* execute:
* Execute a single command
*/
-execute(pp)
-register PLAYER *pp;
+void
+execute(PLAYER *pp)
{
- register char ch;
+ char ch;
ch = pp->p_cbuf[pp->p_ncount++];
-# ifdef FLY
+#ifdef FLY
if (pp->p_flying >= 0) {
switch (ch) {
case CTRL('L'):
}
return;
}
-# endif
+#endif
switch (ch) {
case CTRL('L'):
move_player(pp, LEFTS);
break;
case 'H':
- face(pp, LEFTS);
+ turn_player(pp, LEFTS);
break;
case 'j':
move_player(pp, BELOW);
break;
case 'J':
- face(pp, BELOW);
+ turn_player(pp, BELOW);
break;
case 'k':
move_player(pp, ABOVE);
break;
case 'K':
- face(pp, ABOVE);
+ turn_player(pp, ABOVE);
break;
case 'l':
move_player(pp, RIGHT);
break;
case 'L':
- face(pp, RIGHT);
+ turn_player(pp, RIGHT);
break;
case 'f':
case '1':
case '@':
fire(pp, 10); /* 21x21 BOMB */
break;
-# ifdef OOZE
+#ifdef OOZE
case 'o':
fire_slime(pp, 0); /* SLIME */
break;
case 'P':
fire_slime(pp, 3);
break;
-# endif
+#endif
case 's':
scan(pp);
break;
* move_player:
* Execute a move in the given direction
*/
-move_player(pp, dir)
-register PLAYER *pp;
-int dir;
+static void
+move_player(PLAYER *pp, int dir)
{
- register PLAYER *newp;
- register int x, y;
- register FLAG moved;
- register BULLET *bp;
+ PLAYER *newp;
+ int x, y;
+ bool moved;
+ BULLET *bp;
y = pp->p_y;
x = pp->p_x;
break;
}
- moved = FALSE;
+ moved = false;
switch (Maze[y][x]) {
case SPACE:
-# ifdef RANDOM
+#ifdef RANDOM
case DOOR:
-# endif
- moved = TRUE;
+#endif
+ moved = true;
break;
case WALL1:
case WALL2:
case WALL3:
-# ifdef REFLECT
+#ifdef REFLECT
case WALL4:
case WALL5:
-# endif
+#endif
break;
case MINE:
case GMINE:
else
pickup(pp, y, x, 50, Maze[y][x]);
Maze[y][x] = SPACE;
- moved = TRUE;
+ moved = true;
break;
case SHOT:
case GRENADE:
case SATCHEL:
case BOMB:
-# ifdef OOZE
+#ifdef OOZE
case SLIME:
-# endif
-# ifdef DRONE
+#endif
+#ifdef DRONE
case DSHOT:
-# endif
+#endif
bp = is_bullet(y, x);
if (bp != NULL)
- bp->b_expl = TRUE;
+ bp->b_expl = true;
Maze[y][x] = SPACE;
- moved = TRUE;
+ moved = true;
break;
case LEFTS:
case RIGHT:
checkdam(newp, pp, pp->p_ident, STABDAM, KNIFE);
}
break;
-# ifdef FLY
+#ifdef FLY
case FLYER:
newp = play_at(y, x);
message(newp, "Oooh, there's a short guy waving at you!");
message(pp, "You couldn't quite reach him!");
break;
-# endif
-# ifdef BOOTS
+#endif
+#ifdef BOOTS
case BOOT:
case BOOT_PAIR:
if (Maze[y][x] == BOOT)
else
message(pp, "You can hobble around on one boot.");
Maze[y][x] = SPACE;
- moved = TRUE;
+ moved = true;
break;
-# endif
+#endif
}
if (moved) {
if (pp->p_ncshot > 0)
}
if (pp->p_undershot) {
fixshots(pp->p_y, pp->p_x, pp->p_over);
- pp->p_undershot = FALSE;
+ pp->p_undershot = false;
}
- drawplayer(pp, FALSE);
+ drawplayer(pp, false);
pp->p_over = Maze[y][x];
pp->p_y = y;
pp->p_x = x;
- drawplayer(pp, TRUE);
+ drawplayer(pp, true);
}
}
/*
- * face:
+ * turn_player:
* Change the direction the player is facing
*/
-face(pp, dir)
-register PLAYER *pp;
-register int dir;
+static void
+turn_player(PLAYER *pp, int dir)
{
if (pp->p_face != dir) {
pp->p_face = dir;
- drawplayer(pp, TRUE);
+ drawplayer(pp, true);
}
}
* fire:
* Fire a shot of the given type in the given direction
*/
-fire(pp, req_index)
-register PLAYER *pp;
-register int req_index;
+static void
+fire(PLAYER *pp, int req_index)
{
if (pp == NULL)
return;
-# ifdef DEBUG
+#ifdef DEBUG
if (req_index < 0 || req_index >= MAXBOMB)
message(pp, "What you do?");
-# endif
+#endif
while (req_index >= 0 && pp->p_ammo < shot_req[req_index])
req_index--;
if (req_index < 0) {
outstr(pp, " ", 3);
}
pp->p_ammo -= shot_req[req_index];
- (void) sprintf(Buf, "%3d", pp->p_ammo);
+ (void) snprintf(Buf, sizeof(Buf), "%3d", pp->p_ammo);
cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
outstr(pp, Buf, 3);
add_shot(shot_type[req_index], pp->p_y, pp->p_x, pp->p_face,
- shot_req[req_index], pp, FALSE, pp->p_face);
- pp->p_undershot = TRUE;
+ shot_req[req_index], pp, false, pp->p_face);
+ pp->p_undershot = true;
/*
* Show the object to everyone
showexpl(pp->p_y, pp->p_x, shot_type[req_index]);
for (pp = Player; pp < End_player; pp++)
sendcom(pp, REFRESH);
-# ifdef MONITOR
+#ifdef MONITOR
for (pp = Monitor; pp < End_monitor; pp++)
sendcom(pp, REFRESH);
-# endif
+#endif
}
-# ifdef OOZE
+#ifdef OOZE
/*
* fire_slime:
* Fire a slime shot in the given direction
*/
-fire_slime(pp, req_index)
-register PLAYER *pp;
-register int req_index;
+static void
+fire_slime(PLAYER *pp, int req_index)
{
if (pp == NULL)
return;
-# ifdef DEBUG
+#ifdef DEBUG
if (req_index < 0 || req_index >= MAXSLIME)
message(pp, "What you do?");
-# endif
+#endif
while (req_index >= 0 && pp->p_ammo < slime_req[req_index])
req_index--;
if (req_index < 0) {
outstr(pp, " ", 3);
}
pp->p_ammo -= slime_req[req_index];
- (void) sprintf(Buf, "%3d", pp->p_ammo);
+ (void) snprintf(Buf, sizeof(Buf), "%3d", pp->p_ammo);
cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
outstr(pp, Buf, 3);
add_shot(SLIME, pp->p_y, pp->p_x, pp->p_face,
- slime_req[req_index] * SLIME_FACTOR, pp, FALSE, pp->p_face);
- pp->p_undershot = TRUE;
+ slime_req[req_index] * SLIME_FACTOR, pp, false, pp->p_face);
+ pp->p_undershot = true;
/*
* Show the object to everyone
showexpl(pp->p_y, pp->p_x, SLIME);
for (pp = Player; pp < End_player; pp++)
sendcom(pp, REFRESH);
-# ifdef MONITOR
+#ifdef MONITOR
for (pp = Monitor; pp < End_monitor; pp++)
sendcom(pp, REFRESH);
-# endif
+#endif
}
-# endif
+#endif
/*
* add_shot:
* Create a shot with the given properties
*/
-add_shot(type, y, x, face, charge, owner, expl, over)
-int type;
-int y, x;
-char face;
-int charge;
-PLAYER *owner;
-int expl;
-char over;
+void
+add_shot(int type, int y, int x, char face, int charge,
+ PLAYER *owner, int expl, char over)
{
- register BULLET *bp;
- register int size;
+ BULLET *bp;
+ int size;
switch (type) {
case SHOT:
}
BULLET *
-create_shot(type, y, x, face, charge, size, owner, score, expl, over)
-int type;
-int y, x;
-char face;
-int charge;
-int size;
-PLAYER *owner;
-IDENT *score;
-int expl;
-char over;
+create_shot(int type, int y, int x, char face, int charge,
+ int size, PLAYER *owner, IDENT *score, int expl, char over)
{
- register BULLET *bp;
+ BULLET *bp;
- bp = (BULLET *) malloc(sizeof (BULLET)); /* NOSTRICT */
+ bp = malloc(sizeof(*bp));
if (bp == NULL) {
if (owner != NULL)
message(owner, "Out of memory");
* cloak:
* Turn on or increase length of a cloak
*/
-cloak(pp)
-register PLAYER *pp;
+static void
+cloak(PLAYER *pp)
{
if (pp->p_ammo <= 0) {
message(pp, "No more charges");
return;
}
-# ifdef BOOTS
+#ifdef BOOTS
if (pp->p_nboots > 0) {
message(pp, "Boots are too noisy to cloak!");
return;
}
-# endif
- (void) sprintf(Buf, "%3d", --pp->p_ammo);
+#endif
+ (void) snprintf(Buf, sizeof(Buf), "%3d", --pp->p_ammo);
cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
outstr(pp, Buf, 3);
* scan:
* Turn on or increase length of a scan
*/
-scan(pp)
-register PLAYER *pp;
+static void
+scan(PLAYER *pp)
{
if (pp->p_ammo <= 0) {
message(pp, "No more charges");
return;
}
- (void) sprintf(Buf, "%3d", --pp->p_ammo);
+ (void) snprintf(Buf, sizeof(Buf), "%3d", --pp->p_ammo);
cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
outstr(pp, Buf, 3);
* pickup:
* check whether the object blew up or whether he picked it up
*/
-pickup(pp, y, x, prob, obj)
-register PLAYER *pp;
-register int y, x;
-int prob;
-int obj;
+static void
+pickup(PLAYER *pp, int y, int x, int prob, int obj)
{
- register int req;
+ int req;
switch (obj) {
case MINE:
abort();
}
if (rand_num(100) < prob)
- add_shot(obj, y, x, LEFTS, req, (PLAYER *) NULL,
- TRUE, pp->p_face);
+ add_shot(obj, y, x, LEFTS, req, NULL, true, pp->p_face);
else {
pp->p_ammo += req;
- (void) sprintf(Buf, "%3d", pp->p_ammo);
+ (void) snprintf(Buf, sizeof(Buf), "%3d", pp->p_ammo);
cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
outstr(pp, Buf, 3);
}