X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/22a27dede77166c7bdf1de647d4d2b961fcd92c2..b8313a402e72751bb0d6bed552f055d92fb21620:/sail/dr_2.c diff --git a/sail/dr_2.c b/sail/dr_2.c index 53730515..72c6ef7e 100644 --- a/sail/dr_2.c +++ b/sail/dr_2.c @@ -1,4 +1,4 @@ -/* $NetBSD: dr_2.c,v 1.9 1999/02/10 00:45:45 hubertf Exp $ */ +/* $NetBSD: dr_2.c,v 1.20 2009/03/02 06:43:53 dholland Exp $ */ /* * Copyright (c) 1983, 1993 @@ -12,11 +12,7 @@ * 2. 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. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -38,17 +34,28 @@ #if 0 static char sccsid[] = "@(#)dr_2.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: dr_2.c,v 1.9 1999/02/10 00:45:45 hubertf Exp $"); +__RCSID("$NetBSD: dr_2.c,v 1.20 2009/03/02 06:43:53 dholland Exp $"); #endif #endif /* not lint */ -#include "driver.h" +#include #include +#include +#include "extern.h" +#include "driver.h" #define couldwin(f,t) (f->specs->crew2 > t->specs->crew2 * 1.5) +static int str_end(const char *); +static int score(struct ship *, struct ship *, char *, int); +static void move_ship(struct ship *, const char *, unsigned char *, short *, short *, char *); +static void try(struct ship *, struct ship *, char *, char *, int, int, int, int, int, int *, int); +static void rmend(char *); + +const int dtab[] = {0,1,1,2,3,4,4,5}; /* diagonal distances in x==y */ + void -thinkofgrapples() +thinkofgrapples(void) { struct ship *sp, *sq; char friendly; @@ -63,12 +70,12 @@ thinkofgrapples() continue; if (range(sp, sq) != 1) continue; - if (grappled2(sp, sq)) - if (toughmelee(sp, sq, 0, 0)) + if (grappled2(sp, sq)) { + if (is_toughmelee(sp, sq, 0, 0)) ungrap(sp, sq); else grap(sp, sq); - else if (couldwin(sp, sq)) { + } else if (couldwin(sp, sq)) { grap(sp, sq); sp->file->loadwith = L_GRAPE; } @@ -79,7 +86,7 @@ thinkofgrapples() } void -checkup() +checkup(void) { struct ship *sp, *sq; char explode, sink; @@ -91,7 +98,7 @@ checkup() sink = sp->file->sink; if (explode != 1 && sink != 1) continue; - if (die() < 5) + if (dieroll() < 5) continue; Write(sink == 1 ? W_SINK : W_EXPLODE, sp, 2, 0, 0, 0); Write(W_DIR, sp, 0, 0, 0, 0); @@ -102,7 +109,7 @@ checkup() makemsg(sp, "exploding!"); foreachship(sq) { if (sp != sq && sq->file->dir && range(sp, sq) < 4) - table(RIGGING, L_EXPLODE, sp->specs->guns/13, sq, sp, 6); + table(sp, sq, RIGGING, L_EXPLODE, sp->specs->guns/13, 6); } } else makemsg(sp, "sinking!"); @@ -110,7 +117,7 @@ checkup() } void -prizecheck() +prizecheck(void) { struct ship *sp; @@ -127,11 +134,10 @@ prizecheck() } } -int -strend(str) -char *str; +static int +str_end(const char *str) { - char *p; + const char *p; for (p = str; *p; p++) ; @@ -139,26 +145,18 @@ char *str; } void -closeon(from, to, command, ta, ma, af) -struct ship *from, *to; -char command[]; -int ma, ta, af; +closeon(struct ship *from, struct ship *to, char *command, int ta, int ma, int af) { int high; char temp[10]; temp[0] = command[0] = '\0'; high = -30000; - try(command, temp, ma, ta, af, ma, from->file->dir, from, to, &high, 0); + try(from, to, command, temp, ma, ta, af, ma, from->file->dir, &high, 0); } -int dtab[] = {0,1,1,2,3,4,4,5}; /* diagonal distances in x==y */ - -int -score(movement, ship, to, onlytemp) -char movement[]; -struct ship *ship, *to; -char onlytemp; +static int +score(struct ship *ship, struct ship *to, char *movement, int onlytemp) { char drift; int row, col, dir, total, ran; @@ -169,9 +167,9 @@ char onlytemp; row = fp->row; col = fp->col; drift = fp->drift; - move_ship(movement, ship, &fp->dir, &fp->row, &fp->col, &drift); + move_ship(ship, movement, &fp->dir, &fp->row, &fp->col, &drift); if (!*movement) - (void) strcpy(movement, "d"); + strcpy(movement, "d"); ran = range(ship, to); total = -50 * ran; @@ -188,13 +186,8 @@ char onlytemp; return total; } -void -move_ship(p, ship, dir, row, col, drift) -char *p; -struct ship *ship; -unsigned char *dir; -short *row, *col; -char *drift; +static void +move_ship(struct ship *ship, const char *p, unsigned char *dir, short *row, short *col, char *drift) { int dist; char moved = 0; @@ -233,54 +226,50 @@ char *drift; *drift = 0; } -void -try(command, temp, ma, ta, af, vma, dir, f, t, high, rakeme) -struct ship *f, *t; -int ma, ta, af, vma, dir, *high, rakeme; -char command[], temp[]; +static void +try(struct ship *f, struct ship *t, char *command, char *temp, int ma, int ta, int af, int vma, int dir, int *high, int rakeme) { int new, n; char st[4]; #define rakeyou (gunsbear(f, t) && !gunsbear(t, f)) - if ((n = strend(temp)) < '1' || n > '9') + if ((n = str_end(temp)) < '1' || n > '9') for (n = 1; vma - n >= 0; n++) { - (void) sprintf(st, "%d", n); - (void) strcat(temp, st); - new = score(temp, f, t, rakeme); + sprintf(st, "%d", n); + strcat(temp, st); + new = score(f, t, temp, rakeme); if (new > *high && (!rakeme || rakeyou)) { *high = new; - (void) strcpy(command, temp); + strcpy(command, temp); } - try(command, temp, ma-n, ta, af, vma-n, - dir, f, t, high, rakeme); + try(f, t, command, temp, ma-n, ta, af, vma-n, + dir, high, rakeme); rmend(temp); } - if ((ma > 0 && ta > 0 && (n = strend(temp)) != 'l' && n != 'r') || !strlen(temp)) { - (void) strcat(temp, "r"); - new = score(temp, f, t, rakeme); + if ((ma > 0 && ta > 0 && (n = str_end(temp)) != 'l' && n != 'r') || !strlen(temp)) { + strcat(temp, "r"); + new = score(f, t, temp, rakeme); if (new > *high && (!rakeme || (gunsbear(f, t) && !gunsbear(t, f)))) { *high = new; - (void) strcpy(command, temp); + strcpy(command, temp); } - try(command, temp, ma-1, ta-1, af, min(ma-1, maxmove(f, (dir == 8 ? 1 : dir+1), 0)), (dir == 8 ? 1 : dir+1),f,t,high,rakeme); + try(f, t, command, temp, ma-1, ta-1, af, min(ma-1, maxmove(f, (dir == 8 ? 1 : dir+1), 0)), (dir == 8 ? 1 : dir+1), high, rakeme); rmend(temp); } - if ((ma > 0 && ta > 0 && (n = strend(temp)) != 'l' && n != 'r') || !strlen(temp)){ - (void) strcat(temp, "l"); - new = score(temp, f, t, rakeme); + if ((ma > 0 && ta > 0 && (n = str_end(temp)) != 'l' && n != 'r') || !strlen(temp)){ + strcat(temp, "l"); + new = score(f, t, temp, rakeme); if (new > *high && (!rakeme || (gunsbear(f, t) && !gunsbear(t, f)))){ *high = new; - (void) strcpy(command, temp); + strcpy(command, temp); } - try(command, temp, ma-1, ta-1, af, (min(ma-1,maxmove(f, (dir-1 ? dir-1 : 8), 0))), (dir-1 ? dir -1 : 8), f, t, high, rakeme); + try(f, t, command, temp, ma-1, ta-1, af, (min(ma-1,maxmove(f, (dir-1 ? dir-1 : 8), 0))), (dir-1 ? dir -1 : 8), high, rakeme); rmend(temp); } } -void -rmend(str) -char *str; +static void +rmend(char *str) { char *p;