X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/e9152f6d21d5a8b1e02922e0fc95b71fc21cbd92..82159d673f616b12554c28d5ac54f515fec21e91:/hunt/huntd/execute.c diff --git a/hunt/huntd/execute.c b/hunt/huntd/execute.c index c961d486..e3e5ba2b 100644 --- a/hunt/huntd/execute.c +++ b/hunt/huntd/execute.c @@ -1,20 +1,61 @@ +/* $NetBSD: execute.c,v 1.10 2011/08/31 16:24:56 plunky 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 +#ifndef lint +__RCSID("$NetBSD: execute.c,v 1.10 2011/08/31 16:24:56 plunky Exp $"); +#endif /* not lint */ -# ifdef MONITOR +#include +#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) { @@ -26,20 +67,20 @@ register PLAYER *pp; 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'): @@ -51,7 +92,7 @@ register PLAYER *pp; } return; } -# endif +#endif switch (ch) { case CTRL('L'): @@ -61,25 +102,25 @@ register PLAYER *pp; 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': @@ -118,7 +159,7 @@ register PLAYER *pp; case '@': fire(pp, 10); /* 21x21 BOMB */ break; -# ifdef OOZE +#ifdef OOZE case 'o': fire_slime(pp, 0); /* SLIME */ break; @@ -131,7 +172,7 @@ register PLAYER *pp; case 'P': fire_slime(pp, 3); break; -# endif +#endif case 's': scan(pp); break; @@ -148,14 +189,13 @@ register PLAYER *pp; * 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; + FLAG moved; + BULLET *bp; y = pp->p_y; x = pp->p_x; @@ -178,18 +218,18 @@ int dir; moved = FALSE; switch (Maze[y][x]) { case SPACE: -# ifdef RANDOM +#ifdef RANDOM case DOOR: -# endif +#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: @@ -206,12 +246,12 @@ int dir; 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; @@ -229,14 +269,14 @@ int dir; 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) @@ -259,7 +299,7 @@ int dir; Maze[y][x] = SPACE; moved = TRUE; break; -# endif +#endif } if (moved) { if (pp->p_ncshot > 0) @@ -280,12 +320,11 @@ int dir; } /* - * 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; @@ -297,16 +336,15 @@ register int dir; * 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) { @@ -320,7 +358,7 @@ register int req_index; 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); @@ -334,27 +372,26 @@ register int req_index; 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) { @@ -368,7 +405,7 @@ register int req_index; 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); @@ -382,28 +419,23 @@ register int req_index; 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: @@ -435,20 +467,12 @@ char over; } 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"); @@ -474,20 +498,20 @@ char over; * 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); @@ -503,14 +527,14 @@ register PLAYER *pp; * 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); @@ -526,13 +550,10 @@ register PLAYER *pp; * 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; +void +pickup(PLAYER *pp, int y, int x, int prob, int obj) { - register int req; + int req; switch (obj) { case MINE: @@ -545,11 +566,10 @@ int obj; 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); }