-/* $NetBSD: dr_2.c,v 1.11 1999/09/30 18:01:33 jsm Exp $ */
+/* $NetBSD: dr_2.c,v 1.19 2003/08/07 09:37:41 agc Exp $ */
/*
* Copyright (c) 1983, 1993
* 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.
*
#if 0
static char sccsid[] = "@(#)dr_2.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: dr_2.c,v 1.11 1999/09/30 18:01:33 jsm Exp $");
+__RCSID("$NetBSD: dr_2.c,v 1.19 2003/08/07 09:37:41 agc Exp $");
#endif
#endif /* not lint */
-#include "driver.h"
+#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#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;
}
void
-checkup()
+checkup(void)
{
struct ship *sp, *sq;
char explode, sink;
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);
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!");
}
void
-prizecheck()
+prizecheck(void)
{
struct ship *sp;
}
}
-int
-str_end(str)
- const char *str;
+static int
+str_end(const char *str)
{
const char *p;
}
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);
}
-const 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;
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;
return total;
}
-void
-move_ship(p, ship, dir, row, col, drift)
-const 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;
*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];
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 = str_end(temp)) != 'l' && n != 'r') || !strlen(temp)) {
- (void) strcat(temp, "r");
- new = score(temp, f, t, rakeme);
+ 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 = str_end(temp)) != 'l' && n != 'r') || !strlen(temp)){
- (void) strcat(temp, "l");
- new = score(temp, f, t, rakeme);
+ 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;