-/* $NetBSD: dr_3.c,v 1.3 1995/04/22 10:36:49 cgd Exp $ */
+/* $NetBSD: dr_3.c,v 1.15 2003/08/07 09:37:42 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.
*
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)dr_3.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$NetBSD: dr_3.c,v 1.3 1995/04/22 10:36:49 cgd Exp $";
+__RCSID("$NetBSD: dr_3.c,v 1.15 2003/08/07 09:37:42 agc Exp $");
#endif
#endif /* not lint */
+#include <stdlib.h>
+#include <string.h>
+#include "extern.h"
#include "driver.h"
-moveall() /* move all comp ships */
+static int stillmoving(int);
+static int is_isolated(struct ship *);
+static int push(struct ship *, struct ship *);
+static void step(struct ship *, int, char *);
+
+/* move all comp ships */
+void
+moveall(void)
{
- register struct ship *sp, *sq; /* r11, r10 */
- register int n; /* r9 */
- register int k, l; /* r8, r7 */
+ struct ship *sp, *sq;
+ int n;
+ int k, l;
int row[NSHIP], col[NSHIP], dir[NSHIP], drift[NSHIP];
char moved[NSHIP];
n = 0;
foreachship(sp) {
if (snagged(sp))
- (void) strcpy(sp->file->movebuf, "d");
+ strcpy(sp->file->movebuf, "d");
else
if (*sp->file->movebuf != 'd')
- (void) strcat(sp->file->movebuf, "d");
+ strcat(sp->file->movebuf, "d");
row[n] = sp->file->row;
col[n] = sp->file->col;
dir[n] = sp->file->dir;
if (!sp->file->movebuf[k])
sp->file->movebuf[k+1] = '\0';
else if (sp->file->dir)
- step(sp->file->movebuf[k], sp, &moved[n]);
+ step(sp, sp->file->movebuf[k], &moved[n]);
n++;
}
/*
*/
n = 0;
foreachship(sp) {
- if (sp->file->dir == 0 || isolated(sp))
+ if (sp->file->dir == 0 || is_isolated(sp))
goto cont1;
l = 0;
foreachship(sq) {
if (snagged2(sp, sq) && range(sp, sq) > 1)
snap++;
if (!range(sp, sq) && !fouled2(sp, sq)) {
- makesignal(sp,
- "collision with %s (%c%c)", sq);
- if (die() < 4) {
- makesignal(sp,
- "fouled with %s (%c%c)",
- sq);
- Write(W_FOUL, sp, 0, l, 0, 0, 0);
- Write(W_FOUL, sq, 0, n, 0, 0, 0);
+ makesignal(sp, "collision with $$", sq);
+ if (dieroll() < 4) {
+ makesignal(sp, "fouled with $$",
+ sq);
+ Write(W_FOUL, sp, l, 0, 0, 0);
+ Write(W_FOUL, sq, n, 0, 0, 0);
}
snap++;
}
if (sp->file->dir != 0) {
*sp->file->movebuf = 0;
if (row[n] != sp->file->row)
- Write(W_ROW, sp, 0, sp->file->row, 0, 0, 0);
+ Write(W_ROW, sp, sp->file->row, 0, 0, 0);
if (col[n] != sp->file->col)
- Write(W_COL, sp, 0, sp->file->col, 0, 0, 0);
+ Write(W_COL, sp, sp->file->col, 0, 0, 0);
if (dir[n] != sp->file->dir)
- Write(W_DIR, sp, 0, sp->file->dir, 0, 0, 0);
+ Write(W_DIR, sp, sp->file->dir, 0, 0, 0);
if (drift[n] != sp->file->drift)
- Write(W_DRIFT, sp, 0, sp->file->drift, 0, 0, 0);
+ Write(W_DRIFT, sp, sp->file->drift, 0, 0, 0);
}
n++;
}
}
-stillmoving(k)
-register int k;
+static int
+stillmoving(int k)
{
- register struct ship *sp;
+ struct ship *sp;
foreachship(sp)
if (sp->file->movebuf[k])
return 0;
}
-isolated(ship)
-register struct ship *ship;
+static int
+is_isolated(struct ship *ship)
{
- register struct ship *sp;
+ struct ship *sp;
foreachship(sp) {
if (ship != sp && range(ship, sp) <= 10)
return 1;
}
-push(from, to)
-register struct ship *from, *to;
+static int
+push(struct ship *from, struct ship *to)
{
- register int bs, sb;
+ int bs, sb;
sb = to->specs->guns;
bs = from->specs->guns;
return from < to;
}
-step(com, sp, moved)
-char com;
-register struct ship *sp;
-char *moved;
+static void
+step(struct ship *sp, int com, char *moved)
{
- register int dist;
+ int dist;
switch (com) {
case 'r':
case 'd':
if (!*moved) {
if (windspeed != 0 && ++sp->file->drift > 2 &&
- (sp->specs->class >= 3 && !snagged(sp)
+ ((sp->specs->class >= 3 && !snagged(sp))
|| (turn & 1) == 0)) {
sp->file->row -= dr[winddir];
sp->file->col -= dc[winddir];
}
}
-sendbp(from, to, sections, isdefense)
-register struct ship *from, *to;
-int sections;
-char isdefense;
+void
+sendbp(struct ship *from, struct ship *to, int sections, int isdefense)
{
int n;
- register struct BP *bp;
+ struct BP *bp;
bp = isdefense ? from->file->DBP : from->file->OBP;
for (n = 0; n < NBP && bp[n].turnsent; n++)
;
if (n < NBP && sections) {
- Write(isdefense ? W_DBP : W_OBP, from, 0,
+ Write(isdefense ? W_DBP : W_OBP, from,
n, turn, to->file->index, sections);
if (isdefense)
- makesignal(from, "repelling boarders",
- (struct ship *)0);
+ makemsg(from, "repelling boarders");
else
- makesignal(from, "boarding the %s (%c%c)", to);
+ makesignal(from, "boarding the $$", to);
}
}
-toughmelee(ship, to, isdefense, count)
-register struct ship *ship, *to;
-int isdefense, count;
+int
+is_toughmelee(struct ship *ship, struct ship *to, int isdefense, int count)
{
- register struct BP *bp;
- register obp = 0;
+ struct BP *bp;
+ int obp = 0;
int n, OBP = 0, DBP = 0, dbp = 0;
int qual;
}
if (count || isdefense)
return obp;
- OBP = toughmelee(to, ship, 0, count + 1);
- dbp = toughmelee(ship, to, 1, count + 1);
- DBP = toughmelee(to, ship, 1, count + 1);
+ OBP = is_toughmelee(to, ship, 0, count + 1);
+ dbp = is_toughmelee(ship, to, 1, count + 1);
+ DBP = is_toughmelee(to, ship, 1, count + 1);
if (OBP > obp + 10 || OBP + DBP >= obp + dbp + 10)
return 1;
else
return 0;
}
-reload()
+void
+reload(void)
{
- register struct ship *sp;
+ struct ship *sp;
foreachship(sp) {
sp->file->loadwith = 0;
}
}
-checksails()
+void
+checksails(void)
{
- register struct ship *sp;
- register int rig, full;
+ struct ship *sp;
+ int rig, full;
struct ship *close;
foreachship(sp) {
if (sp->file->captain[0] != 0)
continue;
rig = sp->specs->rig1;
- if (windspeed == 6 || windspeed == 5 && sp->specs->class > 4)
+ if (windspeed == 6 || (windspeed == 5 && sp->specs->class > 4))
rig = 0;
if (rig && sp->specs->crew3) {
close = closestenemy(sp, 0, 0);
} else
full = 0;
if ((sp->file->FS != 0) != full)
- Write(W_FS, sp, 0, full, 0, 0, 0);
+ Write(W_FS, sp, full, 0, 0, 0);
}
}