summaryrefslogtreecommitdiffstats
path: root/sail/dr_2.c
diff options
context:
space:
mode:
Diffstat (limited to 'sail/dr_2.c')
-rw-r--r--sail/dr_2.c79
1 files changed, 54 insertions, 25 deletions
diff --git a/sail/dr_2.c b/sail/dr_2.c
index bbf145c0..56719fbd 100644
--- a/sail/dr_2.c
+++ b/sail/dr_2.c
@@ -1,4 +1,4 @@
-/* $NetBSD: dr_2.c,v 1.22 2009/03/14 18:32:47 dholland Exp $ */
+/* $NetBSD: dr_2.c,v 1.23 2009/03/14 19:35:13 dholland Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)dr_2.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: dr_2.c,v 1.22 2009/03/14 18:32:47 dholland Exp $");
+__RCSID("$NetBSD: dr_2.c,v 1.23 2009/03/14 19:35:13 dholland Exp $");
#endif
#endif /* not lint */
@@ -47,11 +47,15 @@ __RCSID("$NetBSD: dr_2.c,v 1.22 2009/03/14 18:32:47 dholland Exp $");
#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 *, size_t, int);
-static void move_ship(struct ship *, const char *, unsigned char *, short *, short *, int *);
-static void try(struct ship *f, struct ship *t, char *command, size_t commandmax, char *temp, size_t tempmax, int ma, int ta, int af, int vma, int dir, int *high, int rakeme);
-static void rmend(char *);
+static int str_end(const char *);
+static int score(struct ship *, struct ship *, char *, size_t, int);
+static void move_ship(struct ship *, const char *, unsigned char *,
+ short *, short *, int *);
+static void try(struct ship *f, struct ship *t,
+ char *command, size_t commandmax, char *temp, size_t tempmax,
+ int ma, int ta, int af, int vma, int dir, int *high,
+ int rakeme);
+static void rmend(char *);
const int dtab[] = {0,1,1,2,3,4,4,5}; /* diagonal distances in x==y */
@@ -109,11 +113,14 @@ checkup(void)
if (sink != 1) {
makemsg(sp, "exploding!");
foreachship(sq) {
- if (sp != sq && sq->file->dir && range(sp, sq) < 4)
- table(sp, sq, RIGGING, L_EXPLODE, sp->specs->guns/13, 6);
+ if (sp != sq && sq->file->dir &&
+ range(sp, sq) < 4)
+ table(sp, sq, RIGGING, L_EXPLODE,
+ sp->specs->guns/13, 6);
}
- } else
+ } else {
makemsg(sp, "sinking!");
+ }
}
}
@@ -127,9 +134,13 @@ prizecheck(void)
continue;
if (sp->file->struck || sp->file->dir == 0)
continue;
- if (sp->specs->crew1 + sp->specs->crew2 + sp->specs->crew3 > sp->file->pcrew * 6) {
+ if (sp->specs->crew1 + sp->specs->crew2 + sp->specs->crew3 >
+ sp->file->pcrew * 6) {
Writestr(W_SIGNAL, sp, "prize crew overthrown");
- Write(W_POINTS, sp->file->captured, sp->file->captured->file->points - 2 * sp->specs->pts, 0, 0, 0);
+ Write(W_POINTS, sp->file->captured,
+ sp->file->captured->file->points
+ - 2 * sp->specs->pts,
+ 0, 0, 0);
Write(W_CAPTURED, sp, -1, 0, 0, 0);
}
}
@@ -146,18 +157,21 @@ str_end(const char *str)
}
void
-closeon(struct ship *from, struct ship *to, char *command, size_t commandmax, int ta, int ma, int af)
+closeon(struct ship *from, struct ship *to, char *command, size_t commandmax,
+ int ta, int ma, int af)
{
int high;
char temp[10];
temp[0] = command[0] = '\0';
high = -30000;
- try(from, to, command, commandmax, temp, sizeof(temp), ma, ta, af, ma, from->file->dir, &high, 0);
+ try(from, to, command, commandmax, temp, sizeof(temp),
+ ma, ta, af, ma, from->file->dir, &high, 0);
}
static int
-score(struct ship *ship, struct ship *to, char *movement, size_t movementmax, int onlytemp)
+score(struct ship *ship, struct ship *to, char *movement, size_t movementmax,
+ int onlytemp)
{
int drift;
int row, col, dir, total, ran;
@@ -188,7 +202,8 @@ score(struct ship *ship, struct ship *to, char *movement, size_t movementmax, in
}
static void
-move_ship(struct ship *ship, const char *p, unsigned char *dir, short *row, short *col, int *drift)
+move_ship(struct ship *ship, const char *p, unsigned char *dir,
+ short *row, short *col, int *drift)
{
int dist;
char moved = 0;
@@ -228,7 +243,10 @@ move_ship(struct ship *ship, const char *p, unsigned char *dir, short *row, shor
}
static void
-try(struct ship *f, struct ship *t, char *command, size_t commandmax, char *temp, size_t tempmax, int ma, int ta, int af, int vma, int dir, int *high, int rakeme)
+try(struct ship *f, struct ship *t,
+ char *command, size_t commandmax,
+ char *temp, size_t tempmax,
+ int ma, int ta, int af, int vma, int dir, int *high, int rakeme)
{
int new, n;
char st[4];
@@ -243,28 +261,39 @@ try(struct ship *f, struct ship *t, char *command, size_t commandmax, char *temp
*high = new;
strlcpy(command, temp, commandmax);
}
- try(f, t, command, commandmax, temp, tempmax, ma-n, ta, af, vma-n,
- dir, high, rakeme);
+ try(f, t, command, commandmax, temp, tempmax,
+ 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)) {
+ if ((ma > 0 && ta > 0 && (n = str_end(temp)) != 'l' && n != 'r') ||
+ !strlen(temp)) {
strlcat(temp, "r", tempmax);
new = score(f, t, temp, tempmax, rakeme);
- if (new > *high && (!rakeme || (gunsbear(f, t) && !gunsbear(t, f)))) {
+ if (new > *high && (!rakeme ||
+ (gunsbear(f, t) && !gunsbear(t, f)))) {
*high = new;
strlcpy(command, temp, commandmax);
}
- try(f, t, command, commandmax, temp, tempmax, ma-1, ta-1, af, min(ma-1, maxmove(f, (dir == 8 ? 1 : dir+1), 0)), (dir == 8 ? 1 : dir+1), high, rakeme);
+ try(f, t, command, commandmax, temp, tempmax,
+ 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)){
+ if ((ma > 0 && ta > 0 && (n = str_end(temp)) != 'l' && n != 'r') ||
+ !strlen(temp)) {
strlcat(temp, "l", sizeof(temp));
new = score(f, t, temp, tempmax, rakeme);
- if (new > *high && (!rakeme || (gunsbear(f, t) && !gunsbear(t, f)))){
+ if (new > *high && (!rakeme ||
+ (gunsbear(f, t) && !gunsbear(t, f)))) {
*high = new;
strlcpy(command, temp, commandmax);
}
- try(f, t, command, commandmax, temp, tempmax, ma-1, ta-1, af, (min(ma-1,maxmove(f, (dir-1 ? dir-1 : 8), 0))), (dir-1 ? dir -1 : 8), high, rakeme);
+ try(f, t, command, commandmax, temp, tempmax,
+ 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);
}
}