X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/e05192c777ae9a285d9681d4284a44502080945d..dd1a8e39b3a83266b1ed724eeccec96dc60cd87a:/sail/misc.c diff --git a/sail/misc.c b/sail/misc.c index 6dc18c72..91a9e6ed 100644 --- a/sail/misc.c +++ b/sail/misc.c @@ -1,4 +1,4 @@ -/* $NetBSD: misc.c,v 1.3 1995/04/22 10:37:03 cgd Exp $ */ +/* $NetBSD: misc.c,v 1.12 2001/02/05 01:10:10 christos Exp $ */ /* * Copyright (c) 1983, 1993 @@ -33,26 +33,33 @@ * SUCH DAMAGE. */ +#include #ifndef lint #if 0 -static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 5/31/93"; +static char sccsid[] = "@(#)misc.c 8.2 (Berkeley) 4/28/95"; #else -static char rcsid[] = "$NetBSD: misc.c,v 1.3 1995/04/22 10:37:03 cgd Exp $"; +__RCSID("$NetBSD: misc.c,v 1.12 2001/02/05 01:10:10 christos Exp $"); #endif #endif /* not lint */ -#include "externs.h" +#include +#include +#include +#include +#include "extern.h" #include "pathnames.h" #define distance(x,y) (abs(x) >= abs(y) ? abs(x) + abs(y)/2 : abs(y) + abs(x)/2) +static int angle(int, int); + /* XXX */ -range(from, to) -struct ship *from, *to; +int +range(struct ship *from, struct ship *to) { - register bow1r, bow1c, bow2r, bow2c; + int bow1r, bow1c, bow2r, bow2c; int stern1r, stern1c, stern2c, stern2r; - register int bb, bs, sb, ss, result; + int bb, bs, sb, ss, result; if (!to->file->dir) return -1; @@ -75,12 +82,10 @@ struct ship *from, *to; } struct ship * -closestenemy(from, side, anyship) -register struct ship *from; -char side, anyship; +closestenemy(struct ship *from, int side, int anyship) { - register struct ship *sp; - register char a; + struct ship *sp; + char a; int olddist = 30000, dist; struct ship *closest = 0; @@ -103,10 +108,10 @@ char side, anyship; return closest; } -angle(dr, dc) -register dr, dc; +static int +angle(int dr, int dc) { - register i; + int i; if (dc >= 0 && dr > 0) i = 0; @@ -130,11 +135,12 @@ register dr, dc; return i % 8 + 1; } -gunsbear(from, to) /* checks for target bow or stern */ -register struct ship *from, *to; +/* checks for target bow or stern */ +int +gunsbear(struct ship *from, struct ship *to) { int Dr, Dc, i; - register ang; + int ang; Dr = from->file->row - to->file->row; Dc = to->file->col - from->file->col; @@ -151,12 +157,12 @@ register struct ship *from, *to; return 0; } -portside(from, on, quick) -register struct ship *from, *on; -int quick; /* returns true if fromship is */ -{ /* shooting at onship's starboard side */ - register ang; - register Dr, Dc; +/* returns true if fromship is shooting at onship's starboard side */ +int +portside(struct ship *from, struct ship *on, int quick) +{ + int ang; + int Dr, Dc; Dr = from->file->row - on->file->row; Dc = on->file->col - from->file->col; @@ -171,10 +177,10 @@ int quick; /* returns true if fromship is */ return ang < 5; } -colours(sp) -register struct ship *sp; +int +colours(struct ship *sp) { - register char flag; + char flag = '\0'; if (sp->file->struck) flag = '!'; @@ -188,19 +194,22 @@ register struct ship *sp; return sp->file->FS ? flag : tolower(flag); } -#include -log(s) -register struct ship *s; +void +logger(struct ship *s) { FILE *fp; int persons; int n; struct logs log[NLOG]; float net; - register struct logs *lp; + struct logs *lp; - if ((fp = fopen(_PATH_LOGFILE, "r+")) == NULL) + setegid(egid); + if ((fp = fopen(_PATH_LOGFILE, "r+")) == NULL) { + setegid(gid); return; + } + setegid(gid); #ifdef LOCK_EX if (flock(fileno(fp), LOCK_EX) < 0) return; @@ -213,27 +222,24 @@ register struct ship *s; = lp->l_gamenum = lp->l_netpoints = 0; rewind(fp); if (persons < 0) - (void) putw(1, fp); + putw(1, fp); else - (void) putw(persons + 1, fp); + putw(persons + 1, fp); for (lp = log; lp < &log[NLOG]; lp++) if (net > (float)lp->l_netpoints / scene[lp->l_gamenum].ship[lp->l_shipnum].specs->pts) { - (void) fwrite((char *)log, - sizeof (struct logs), lp - log, fp); - (void) strcpy(log[NLOG-1].l_name, s->file->captain); + fwrite((char *)log, sizeof (struct logs), lp - log, fp); + strcpy(log[NLOG-1].l_name, s->file->captain); log[NLOG-1].l_uid = getuid(); log[NLOG-1].l_shipnum = s->file->index; log[NLOG-1].l_gamenum = game; log[NLOG-1].l_netpoints = s->file->points; - (void) fwrite((char *)&log[NLOG-1], - sizeof (struct logs), 1, fp); - (void) fwrite((char *)lp, - sizeof (struct logs), &log[NLOG-1] - lp, fp); + fwrite((char *)&log[NLOG-1], sizeof (struct logs), 1, fp); + fwrite((char *)lp, sizeof (struct logs), &log[NLOG-1] - lp, fp); break; } #ifdef LOCK_EX - (void) flock(fileno(fp), LOCK_UN); + flock(fileno(fp), LOCK_UN); #endif - (void) fclose(fp); + fclose(fp); }