X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/4c39d3d5d3a9a029eecd375d4c55d91ed234cc9c..82159d673f616b12554c28d5ac54f515fec21e91:/hunt/huntd/execute.c diff --git a/hunt/huntd/execute.c b/hunt/huntd/execute.c index 5c59b32e..e3e5ba2b 100644 --- a/hunt/huntd/execute.c +++ b/hunt/huntd/execute.c @@ -1,4 +1,4 @@ -/* $NetBSD: execute.c,v 1.5 2008/01/28 03:23:29 dholland Exp $ */ +/* $NetBSD: execute.c,v 1.10 2011/08/31 16:24:56 plunky Exp $ */ /* * Copyright (c) 1983-2003, Regents of the University of California. * All rights reserved. @@ -32,31 +32,30 @@ #include #ifndef lint -__RCSID("$NetBSD: execute.c,v 1.5 2008/01/28 03:23:29 dholland Exp $"); +__RCSID("$NetBSD: execute.c,v 1.10 2011/08/31 16:24:56 plunky Exp $"); #endif /* not lint */ -# include -# include "hunt.h" +#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 *); +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 +#ifdef MONITOR /* * mon_execute: * Execute a single monitor command */ void -mon_execute(pp) - PLAYER *pp; +mon_execute(PLAYER *pp) { - char ch; + char ch; ch = pp->p_cbuf[pp->p_ncount++]; switch (ch) { @@ -68,21 +67,20 @@ mon_execute(pp) break; } } -# endif +#endif /* * execute: * Execute a single command */ void -execute(pp) - PLAYER *pp; +execute(PLAYER *pp) { - 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'): @@ -94,7 +92,7 @@ execute(pp) } return; } -# endif +#endif switch (ch) { case CTRL('L'): @@ -161,7 +159,7 @@ execute(pp) case '@': fire(pp, 10); /* 21x21 BOMB */ break; -# ifdef OOZE +#ifdef OOZE case 'o': fire_slime(pp, 0); /* SLIME */ break; @@ -174,7 +172,7 @@ execute(pp) case 'P': fire_slime(pp, 3); break; -# endif +#endif case 's': scan(pp); break; @@ -192,14 +190,12 @@ execute(pp) * Execute a move in the given direction */ static void -move_player(pp, dir) - PLAYER *pp; - int dir; +move_player(PLAYER *pp, int dir) { - PLAYER *newp; - int x, y; - FLAG moved; - BULLET *bp; + PLAYER *newp; + int x, y; + FLAG moved; + BULLET *bp; y = pp->p_y; x = pp->p_x; @@ -222,18 +218,18 @@ move_player(pp, 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: @@ -250,12 +246,12 @@ move_player(pp, 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; @@ -273,14 +269,14 @@ move_player(pp, 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) @@ -303,7 +299,7 @@ move_player(pp, dir) Maze[y][x] = SPACE; moved = TRUE; break; -# endif +#endif } if (moved) { if (pp->p_ncshot > 0) @@ -328,9 +324,7 @@ move_player(pp, dir) * Change the direction the player is facing */ static void -turn_player(pp, dir) - PLAYER *pp; - int dir; +turn_player(PLAYER *pp, int dir) { if (pp->p_face != dir) { pp->p_face = dir; @@ -343,16 +337,14 @@ turn_player(pp, dir) * Fire a shot of the given type in the given direction */ static void -fire(pp, req_index) - PLAYER *pp; - int req_index; +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) { @@ -366,7 +358,7 @@ fire(pp, 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); @@ -380,28 +372,26 @@ fire(pp, 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 */ static void -fire_slime(pp, req_index) - PLAYER *pp; - int req_index; +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) { @@ -415,7 +405,7 @@ fire_slime(pp, 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); @@ -429,29 +419,23 @@ fire_slime(pp, 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 */ void -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; +add_shot(int type, int y, int x, char face, int charge, + PLAYER *owner, int expl, char over) { - BULLET *bp; - int size; + BULLET *bp; + int size; switch (type) { case SHOT: @@ -483,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) { - 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"); @@ -523,20 +499,19 @@ create_shot(type, y, x, face, charge, size, owner, score, expl, over) * Turn on or increase length of a cloak */ static void -cloak(pp) - PLAYER *pp; +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); @@ -553,14 +528,13 @@ cloak(pp) * Turn on or increase length of a scan */ static void -scan(pp) - PLAYER *pp; +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); @@ -577,13 +551,9 @@ scan(pp) * check whether the object blew up or whether he picked it up */ void -pickup(pp, y, x, prob, obj) - PLAYER *pp; - int y, x; - int prob; - int obj; +pickup(PLAYER *pp, int y, int x, int prob, int obj) { - int req; + int req; switch (obj) { case MINE: @@ -596,11 +566,10 @@ pickup(pp, y, x, prob, 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); }