got rid of unnecessary variables
authorEdward Wang <edward@ucbvax.Berkeley.EDU>
Tue, 11 Oct 1983 12:11:33 +0000 (04:11 -0800)
committerEdward Wang <edward@ucbvax.Berkeley.EDU>
Tue, 11 Oct 1983 12:11:33 +0000 (04:11 -0800)
SCCS-vsn: games/sail/Makefile 1.12
SCCS-vsn: games/sail/dr_1.c 1.5
SCCS-vsn: games/sail/dr_2.c 1.4
SCCS-vsn: games/sail/dr_3.c 1.5
SCCS-vsn: games/sail/extern.h 1.7
SCCS-vsn: games/sail/game.c 1.5
SCCS-vsn: games/sail/globals.c 1.6
SCCS-vsn: games/sail/pl_1.c 1.10
SCCS-vsn: games/sail/pl_2.c 1.5
SCCS-vsn: games/sail/pl_3.c 1.2
SCCS-vsn: games/sail/pl_4.c 1.3
SCCS-vsn: games/sail/misc.c 1.3

12 files changed:
usr/src/games/sail/Makefile
usr/src/games/sail/dr_1.c
usr/src/games/sail/dr_2.c
usr/src/games/sail/dr_3.c
usr/src/games/sail/extern.h
usr/src/games/sail/game.c
usr/src/games/sail/globals.c
usr/src/games/sail/misc.c
usr/src/games/sail/pl_1.c
usr/src/games/sail/pl_2.c
usr/src/games/sail/pl_3.c
usr/src/games/sail/pl_4.c

index d29d7c2..9bf7394 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Sail - Wooden Ships And Iron Men
 #
 #
 # Sail - Wooden Ships And Iron Men
 #
-# Makefile     @(#)Makefile    1.11 83/10/05
+# Makefile     @(#)Makefile    1.12 83/10/10
 #
 CC= cc
 CTAGS= ctags -w
 #
 CC= cc
 CTAGS= ctags -w
@@ -11,27 +11,26 @@ DFILES= driver1.c driver2.c driver3.c grap.c boarders.c
 DOBJS= driver1.o driver2.o driver3.o grap.o boarders.o
 PFILES= player1.c player2.c player3.c player4.c version.c
 POBJS= player1.o player2.o player3.o player4.o version.o
 DOBJS= driver1.o driver2.o driver3.o grap.o boarders.o
 PFILES= player1.c player2.c player3.c player4.c version.c
 POBJS= player1.o player2.o player3.o player4.o version.o
-COMMONFILES= assorted.c game.c globals.c misc.c parties.c screen.c
-COMMONOBJS= assorted.o game.o globals.o misc.o parties.o screen.o
+COMMONFILES= assorted.c game.c globals.c misc.c parties.c sync.c
+COMMONOBJS= assorted.o game.o globals.o misc.o parties.o sync.o
 LFILES= sail.log.c
 LOBJS= sail.log.o
 
 HDRS= externs.h player.h driver.h machdep.h
 OTHERFILES= Makefile sail.6
 CTAGFILES= ${DFILES} ${PFILES} ${LFILES} ${COMMONFILES}
 LFILES= sail.log.c
 LOBJS= sail.log.o
 
 HDRS= externs.h player.h driver.h machdep.h
 OTHERFILES= Makefile sail.6
 CTAGFILES= ${DFILES} ${PFILES} ${LFILES} ${COMMONFILES}
-JUNKFILES= sail driver sail.log sail.doc
-PLIBS= -lcurses -ltermlib machdep.o
+JUNKFILES= make.out
+PLIBS= -lcurses -ltermlib
 DLIBS=
 LLIBS=
 SAILMASTER= daemon
 SAIL= sail
 DRIVER= lib/saildriver
 SAIL.LOG= sail.log
 DLIBS=
 LLIBS=
 SAILMASTER= daemon
 SAIL= sail
 DRIVER= lib/saildriver
 SAIL.LOG= sail.log
-SAIL.DOC= sail.doc
 LOGFILE= lib/saillog
 TARGET= /usr/games
 
 LOGFILE= lib/saillog
 TARGET= /usr/games
 
-all: sail driver sail.log sail.doc
+all: sail driver sail.log
 
 sail: ${POBJS} ${COMMONOBJS}
        cc -O ${COMMONOBJS} ${POBJS} ${PLIBS} -o sail
 
 sail: ${POBJS} ${COMMONOBJS}
        cc -O ${COMMONOBJS} ${POBJS} ${PLIBS} -o sail
@@ -42,9 +41,6 @@ driver: ${DOBJS} ${COMMONOBJS}
 sail.log: ${LOBJS} globals.o
        cc -O ${LOBJS} globals.o -o sail.log
 
 sail.log: ${LOBJS} globals.o
        cc -O ${LOBJS} globals.o -o sail.log
 
-sail.doc: sail.6
-#      nroff -man sail.6 > sail.doc
-
 lint:
        lint -z $(PFILES) $(COMMONFILES) -lcurses
        lint -z $(DFILES) $(COMMONFILES)
 lint:
        lint -z $(PFILES) $(COMMONFILES) -lcurses
        lint -z $(DFILES) $(COMMONFILES)
@@ -66,12 +62,11 @@ profile: sail.prof
 clean: 
        rm -f ${DOBJS} ${POBJS} ${LOBJS} ${COMMONOBJS} ${JUNKFILES}
 
 clean: 
        rm -f ${DOBJS} ${POBJS} ${LOBJS} ${COMMONOBJS} ${JUNKFILES}
 
-install: sail driver sail.log sail.doc ${TARGET}/${LOGFILE}
+install: sail driver sail.log ${TARGET}/${LOGFILE}
        install -s -m 4711 -o ${SAILMASTER} sail ${TARGET}/${SAIL}
        install -s -m 4711 -o ${SAILMASTER} driver ${TARGET}/${DRIVER}
        install -s -m 711 sail.log ${TARGET}/${SAIL.LOG}
        install sail.6 /usr/man/man6
        install -s -m 4711 -o ${SAILMASTER} sail ${TARGET}/${SAIL}
        install -s -m 4711 -o ${SAILMASTER} driver ${TARGET}/${DRIVER}
        install -s -m 711 sail.log ${TARGET}/${SAIL.LOG}
        install sail.6 /usr/man/man6
-#      cp sail.doc ${TARGET}/${SAIL.DOC}
 
 ${TARGET}/${LOGFILE}:
        cp /dev/null ${TARGET}/${LOGFILE}
 
 ${TARGET}/${LOGFILE}:
        cp /dev/null ${TARGET}/${LOGFILE}
index cc31ecb..38287c5 100644 (file)
@@ -1,9 +1,73 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)dr_1.c      1.4 83/07/20";
+static char *sccsid = "@(#)dr_1.c      1.5 83/10/10";
 #endif
 
 #include "driver.h"
 
 #endif
 
 #include "driver.h"
 
+main(argc, argv)
+int argc;
+char **argv;
+{
+       register int n;
+       register struct ship *sp;
+       int nat[NNATION];
+
+       if (argc != 2)
+               exit(1);
+       (void) signal(SIGINT, SIG_IGN);
+       (void) signal(SIGQUIT, SIG_IGN);
+       (void) srand(getpid());
+       /* ;;; add code here to check the game number. */
+       game = atoi(argv[1]);
+       cc = &scene[game];
+       ls = &cc->ship[cc->vessels];
+       if (sync_open() < 0) {
+               perror("driver: syncfile");
+               exit(1);
+       }
+       for (n = 0; n < NNATION; n++)
+               nat[n] = 0;
+       foreachship(sp) {
+               sp->file = (struct File *) calloc(1, sizeof (struct File));
+               if (sp == NULL) {
+                       (void) printf("driver: OUT OF MEMORY\n");
+                       exit(0);
+               }
+               sp->file->loadL = L_ROUND;
+               sp->file->loadR = L_ROUND;
+               sp->file->readyR = R_LOADED|R_INITIAL;
+               sp->file->readyL = R_LOADED|R_INITIAL;
+               sp->file->stern = nat[sp->nationality]++;
+               sp->file->dir = sp->shipdir;
+               sp->file->row = sp->shiprow;
+               sp->file->col = sp->shipcol;
+       }
+       windspeed = cc->windspeed;
+       winddir = cc->winddir;
+       for (;;) {
+               Sync();
+               next();
+               unfoul();
+               checkup();
+               prizecheck();
+               moveall();
+               /*
+               readpos();
+               */
+               thinkofgrapples();
+               boardcomp();
+               compcombat();
+               /*
+               readpos();
+               */
+               resolve();
+               reload();
+               checksails();
+               Sync();
+               sleep(7);
+       }
+}
+
 unfoul()
 {
        register int k;
 unfoul()
 {
        register int k;
@@ -351,17 +415,12 @@ compcombat()
 next()
 {
        if (++turn % 55 == 0)
 next()
 {
        if (++turn % 55 == 0)
-               if (cc->time)
-                       cc->time = 0;
+               if (alive)
+                       alive = 0;
                else
                else
-                       cc->people = 0;         /* die if no one */
-       if (cc->people <= 0 || windspeed == 7) {
-               char string[25];
-
-               (void) fclose(syncfile);
-               (void) sprintf(string, "/tmp/.%d", game);
-               if (unlink(string) == -1)
-                       perror(string);
+                       people = 0;
+       if (people <= 0 || windspeed == 7) {
+               sync_close(1);
                exit(0);
        }
        Write(W_TURN, SHIP(0), 0, turn, 0, 0, 0);
                exit(0);
        }
        Write(W_TURN, SHIP(0), 0, turn, 0, 0, 0);
@@ -407,66 +466,3 @@ next()
                }
        }
 }
                }
        }
 }
-
-main(argc, argv)
-int argc;
-char **argv;
-{
-       register int n;
-       char file[25];
-       register struct ship *sp;
-       int nat[NNATION];
-
-       if (argc != 2)
-               exit(1);
-       (void) signal(SIGINT, SIG_IGN);
-       (void) signal(SIGQUIT, SIG_IGN);
-       (void) srand(getpid());
-       /* ;;; add code here to check the game number. */
-       (void) sprintf(file, "/tmp/.%s", argv[1]);
-       for (n = 0; access(file, 0) < 0 && n < 20; n++)
-               sleep(5);
-       syncfile = fopen(file, "r+");
-       if (syncfile == NULL) {
-               perror(file);
-               exit(1);
-       }
-       game = atoi(argv[1]);
-       cc = &scene[game];
-       ls = &cc->ship[cc->vessels];
-       for (n = 0; n < NNATION; n++)
-               nat[n] = 0;
-       foreachship(sp) {
-               sp->file = (struct File *) calloc(1, sizeof (struct File));
-               if (sp == NULL) {
-                       (void) printf("driver: OUT OF MEMORY\n");
-                       exit(0);
-               }
-               sp->file->loadL = L_ROUND;
-               sp->file->loadR = L_ROUND;
-               sp->file->readyR = R_LOADED|R_INITIAL;
-               sp->file->readyL = R_LOADED|R_INITIAL;
-               sp->file->stern = nat[sp->nationality]++;
-       }
-       for (;;) {
-               Sync();
-               windspeed = cc->windspeed;
-               winddir = cc->winddir;
-               turn = cc->turn;
-               next();
-               unfoul();
-               checkup();
-               prizecheck();
-               moveall();
-               readpos();
-               thinkofgrapples();
-               boardcomp();
-               compcombat();
-               readpos();
-               resolve();
-               reload();
-               checksails();
-               Sync();
-               sleep(7);
-       }
-}
index 6a57dd1..df5b8de 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)dr_2.c      1.3 83/10/05";
+static char *sccsid = "@(#)dr_2.c      1.4 83/10/10";
 #endif
 
 #include "driver.h"
 #endif
 
 #include "driver.h"
@@ -42,7 +42,9 @@ checkup()
        register struct ship *sp, *sq;
        register char explode, sink;
 
        register struct ship *sp, *sq;
        register char explode, sink;
 
+       /*
        readpos();
        readpos();
+       */
        foreachship(sp) {
                explode = sp->file->explode;
                sink = sp->file->sink;
        foreachship(sp) {
                explode = sp->file->explode;
                sink = sp->file->sink;
@@ -162,22 +164,24 @@ moveship(ship, movement)
 struct ship *ship;
 char *movement;
 {
 struct ship *ship;
 char *movement;
 {
-       char drift;
        register struct File *fp = ship->file;
        register struct File *fp = ship->file;
+       int drift = fp->drift;
+       int row = fp->row;
+       int col = fp->col;
+       int dir = fp->dir;
 
        if (fp->dir == 0)
                return;
 
        if (fp->dir == 0)
                return;
-       drift = fp->drift;
        move(movement, ship, &fp->dir, &fp->row, &fp->col, &drift);
        if (drift > 2 || *movement == 0)
                (void) strcat(movement, "d");
        move(movement, ship, &fp->dir, &fp->row, &fp->col, &drift);
        if (drift > 2 || *movement == 0)
                (void) strcat(movement, "d");
-       if (drift != fp->drift)
+       if (fp->drift != drift)
                Write(W_DRIFT, ship, 0, drift, 0, 0, 0);
                Write(W_DRIFT, ship, 0, drift, 0, 0, 0);
-       if (fp->row != ship->shiprow)
+       if (fp->row != row)
                Write(W_SHIPROW, ship, 0, fp->row, 0, 0, 0);
                Write(W_SHIPROW, ship, 0, fp->row, 0, 0, 0);
-       if (fp->col != ship->shipcol)
+       if (fp->col != col)
                Write(W_SHIPCOL, ship, 0, fp->col, 0, 0, 0);
                Write(W_SHIPCOL, ship, 0, fp->col, 0, 0, 0);
-       if (fp->dir != ship->shipdir)
+       if (fp->dir != dir)
                Write(W_SHIPDIR, ship, 0, fp->dir, 0, 0, 0);
 }
 
                Write(W_SHIPDIR, ship, 0, fp->dir, 0, 0, 0);
 }
 
index c8721a4..41ec53e 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)dr_3.c      1.4 83/07/20";
+static char *sccsid = "@(#)dr_3.c      1.5 83/10/10";
 #endif
 
 #include "driver.h"
 #endif
 
 #include "driver.h"
@@ -10,7 +10,8 @@ moveall()             /* move all comp ships */
        register int n;                         /* r9 */
        struct ship *closest;
        register int k, l, m, ma;               /* r8, r7, r6, */
        register int n;                         /* r9 */
        struct ship *closest;
        register int k, l, m, ma;               /* r8, r7, r6, */
-       int ta, af;
+       int ta;
+       char af;
        int row[NSHIP], col[NSHIP], dir[NSHIP], r1, r2, c1, c2, d1, d2;
        char clast[NSHIP][sizeof SHIP(0)->file->last];
 
        int row[NSHIP], col[NSHIP], dir[NSHIP], r1, r2, c1, c2, d1, d2;
        char clast[NSHIP][sizeof SHIP(0)->file->last];
 
@@ -18,13 +19,11 @@ moveall()           /* move all comp ships */
         * first try to create moves for OUR ships
         */
        foreachship(sp) {
         * first try to create moves for OUR ships
         */
        foreachship(sp) {
-               if (sp->file->captain[0] || sp->shipdir == 0)
+               if (sp->file->captain[0] || sp->file->dir == 0)
                        continue;
                if (!sp->file->struck && windspeed && !snagged(sp)
                    && sp->specs->crew3) {
                        continue;
                if (!sp->file->struck && windspeed && !snagged(sp)
                    && sp->specs->crew3) {
-                       ta = maxturns(sp);
-                       af = ta & 0100000;
-                       ta &= 077777;
+                       ta = maxturns(sp, &af);
                        ma = maxmove(sp, sp->file->dir, 0);
                        closest = closestenemy(sp, 0, 0);
                        if (closest == 0)
                        ma = maxmove(sp, sp->file->dir, 0);
                        closest = closestenemy(sp, 0, 0);
                        if (closest == 0)
index c3ddd3f..e2cb9bb 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * @(#)extern.h        1.6 83/10/05
+ * @(#)extern.h        1.7 83/10/10
  */
 #include <stdio.h>
 #include <signal.h>
  */
 #include <stdio.h>
 #include <signal.h>
@@ -64,7 +64,7 @@
 #define W_LAST         13
 #define W_OBP          14
 #define W_PCREW                15
 #define W_LAST         13
 #define W_OBP          14
 #define W_PCREW                15
-#define W_PEOPLE       16
+/* 16 */
 #define W_POINTS       17
 #define W_QUAL         18
 /* 19 */
 #define W_POINTS       17
 #define W_QUAL         18
 /* 19 */
@@ -76,7 +76,7 @@
 #define W_SINK         25
 #define W_STRUCK       26
 #define W_TA           27
 #define W_SINK         25
 #define W_STRUCK       26
 #define W_TA           27
-#define W_TIME         28
+#define W_ALIVE                28
 #define W_TURN         29
 #define W_WIND         30
 #define W_FS           31
 #define W_TURN         29
 #define W_WIND         30
 #define W_FS           31
@@ -85,6 +85,8 @@
 #define W_RIG2         34
 #define W_RIG3         35
 #define W_RIG4         36
 #define W_RIG2         34
 #define W_RIG3         35
 #define W_RIG4         36
+#define W_BEGIN                37
+#define W_END          38
 
 struct logs {
        char l_name[20];
 
 struct logs {
        char l_name[20];
@@ -160,9 +162,6 @@ struct scenario {
        char winddir;                   /* 0 */
        char windspeed;                 /* 2 */
        char windchange;                /* 4 */
        char winddir;                   /* 0 */
        char windspeed;                 /* 2 */
        char windchange;                /* 4 */
-       short turn;                     /* 6 */
-       char people;                    /* 8 */
-       char time;                      /* 10 */
        char vessels;                   /* 12 */
        char *name;                     /* 14 */
        struct ship ship[NSHIP];        /* 16 */
        char vessels;                   /* 12 */
        char *name;                     /* 14 */
        struct ship ship[NSHIP];        /* 16 */
@@ -225,11 +224,12 @@ char rangeofshot[];
 
 char dr[], dc[];
 
 
 char dr[], dc[];
 
-long lastsync;
-int winddir, windspeed, turn;
+int winddir;
+int windspeed;
+int turn;
 int game;
 int game;
-char Outbuf[BUFSIZE];
-FILE *syncfile;
+int alive;
+int people;
 
 char *info();
 char *quality();
 
 char *info();
 char *quality();
index e8de60b..59bbc4f 100644 (file)
@@ -1,20 +1,20 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)game.c      1.4 83/07/20";
+static char *sccsid = "@(#)game.c      1.5 83/10/10";
 #endif
 
 #include "externs.h"
 
 #endif
 
 #include "externs.h"
 
-maxturns(ship)
+maxturns(ship, af)
 register struct ship *ship;
 register struct ship *ship;
+char *af;
 {
        register int turns;
 
        turns = ship->specs->ta;
 {
        register int turns;
 
        turns = ship->specs->ta;
-       if (ship->file->drift > 1 && turns) {
+       if (*af = (ship->file->drift > 1 && turns)) {
                turns--;
                if (ship->file->FS == 1)
                        turns = 0;
                turns--;
                if (ship->file->FS == 1)
                        turns = 0;
-               turns |= 0100000;
        }
        return turns;
 }
        }
        return turns;
 }
index 0205da1..6fb9cc2 100644 (file)
@@ -1,6 +1,6 @@
 /*LINTLIBRARY*/
 #ifndef lint
 /*LINTLIBRARY*/
 #ifndef lint
-static char *sccsid = "@(#)globals.c   1.5 83/10/05";
+static char *sccsid = "@(#)globals.c   1.6 83/10/10";
 #endif
 
 #include "externs.h"
 #endif
 
 #include "externs.h"
@@ -10,24 +10,21 @@ struct scenario scene[] = {
         * int winddir;
         * int windspeed;
         * int windchange;
         * int winddir;
         * int windspeed;
         * int windchange;
-        * int turn;
-        * int people;
-        * int time;
         * int vessels;
         * char *name;
         * struct ship ship[NSHIP];
         */
         * int vessels;
         * char *name;
         * struct ship ship[NSHIP];
         */
-       5, 3, 5, 0, 1, 0, 2, "Ranger vs. Drake",
+       5, 3, 5, 2, "Ranger vs. Drake",
        {
                { "Ranger",             specs+0,  N_A,  7, 20, 4, 0 },
                { "Drake",              specs+1,  N_B,  7, 31, 5, 0 }
        },
        {
                { "Ranger",             specs+0,  N_A,  7, 20, 4, 0 },
                { "Drake",              specs+1,  N_B,  7, 31, 5, 0 }
        },
-       1, 3, 6, 0, 1, 0, 2, "The Battle of Flamborough Head",
+       1, 3, 6, 2, "The Battle of Flamborough Head",
        {
                { "Bonhomme Rich",      specs+2,  N_A, 13, 40, 2, 0 },
                { "Serapis",            specs+3,  N_B,  2, 42, 2, 0 }
        },
        {
                { "Bonhomme Rich",      specs+2,  N_A, 13, 40, 2, 0 },
                { "Serapis",            specs+3,  N_B,  2, 42, 2, 0 }
        },
-       5, 5, 5, 0, 1, 0, 10, "Arbuthnot and Des Touches",
+       5, 5, 5, 10, "Arbuthnot and Des Touches",
        {
                { "America",            specs+4,  N_B,  7, 37, 4, 0 },
                { "Befford",            specs+5,  N_B,  5, 35, 4, 0 },
        {
                { "America",            specs+4,  N_B,  7, 37, 4, 0 },
                { "Befford",            specs+5,  N_B,  5, 35, 4, 0 },
@@ -40,7 +37,7 @@ struct scenario scene[] = {
                { "Provence",           specs+11, N_F, 12, 50, 4, 0 },
                { "Romulus",            specs+12, N_F, 20, 58, 4, 0 }
        },
                { "Provence",           specs+11, N_F, 12, 50, 4, 0 },
                { "Romulus",            specs+12, N_F, 20, 58, 4, 0 }
        },
-       1, 3, 5, 0, 1, 0, 10, "Suffren and Hughes",
+       1, 3, 5, 10, "Suffren and Hughes",
        {
                { "Monmouth",           specs+52, N_B,  9, 45, 2, 0 },
                { "Hero",               specs+5,  N_B, 13, 49, 2, 0 },
        {
                { "Monmouth",           specs+52, N_B,  9, 45, 2, 0 },
                { "Hero",               specs+5,  N_B, 13, 49, 2, 0 },
@@ -53,32 +50,32 @@ struct scenario scene[] = {
                { "Brilliant",          specs+49, N_F, -1, 51, 4, 0 },
                { "Sphinx",             specs+51, N_F, -5, 47, 4, 0 }
        },
                { "Brilliant",          specs+49, N_F, -1, 51, 4, 0 },
                { "Sphinx",             specs+51, N_F, -5, 47, 4, 0 }
        },
-       1, 3, 4, 0, 1, 0, 2, "Nymphe vs. Cleopatre",
+       1, 3, 4, 2, "Nymphe vs. Cleopatre",
        {
                { "Nymphe",             specs+14, N_B, 13, 30, 2, 0 },
                { "Cleopatre",          specs+15, N_F,  3, 41, 2, 0 }
        },
        {
                { "Nymphe",             specs+14, N_B, 13, 30, 2, 0 },
                { "Cleopatre",          specs+15, N_F,  3, 41, 2, 0 }
        },
-       1, 3, 5, 0, 1, 0, 2, "Mars vs. Hercule",
+       1, 3, 5, 2, "Mars vs. Hercule",
        {
                { "Mars",               specs+16, N_B, 13, 30, 2, 0 },
                { "Hercule",            specs+17, N_F,  3, 41, 2, 0 }
        },
        {
                { "Mars",               specs+16, N_B, 13, 30, 2, 0 },
                { "Hercule",            specs+17, N_F,  3, 41, 2, 0 }
        },
-       5, 3, 5, 0, 1, 0, 2, "Ambuscade vs. Baionnaise",
+       5, 3, 5, 2, "Ambuscade vs. Baionnaise",
        {
                { "Ambuscade",          specs+18, N_B, 13, 30, 2, 0 },
                { "Baionnaise",         specs+19, N_F,  3, 41, 2, 0 }
        },
        {
                { "Ambuscade",          specs+18, N_B, 13, 30, 2, 0 },
                { "Baionnaise",         specs+19, N_F,  3, 41, 2, 0 }
        },
-       1, 5, 6, 0, 1, 0, 2, "Constellation vs. Insurgent",
+       1, 5, 6, 2, "Constellation vs. Insurgent",
        {
                { "Constellation",      specs+20, N_A,  9, 50, 8, 0 },
                { "Insurgent",          specs+22, N_F,  4, 24, 2, 0 }
        },
        {
                { "Constellation",      specs+20, N_A,  9, 50, 8, 0 },
                { "Insurgent",          specs+22, N_F,  4, 24, 2, 0 }
        },
-       1, 3, 5, 0, 1, 0, 2, "Constellation vs. Vengeance",
+       1, 3, 5, 2, "Constellation vs. Vengeance",
        {
                { "Constellation",      specs+20, N_A, 12, 40, 2, 0 },
                { "Vengeance",          specs+21, N_F,  1, 43, 2, 0 }
        },
        {
                { "Constellation",      specs+20, N_A, 12, 40, 2, 0 },
                { "Vengeance",          specs+21, N_F,  1, 43, 2, 0 }
        },
-       1, 3, 6, 0, 1, 0, 10, "The Battle of Lissa",
+       1, 3, 6, 10, "The Battle of Lissa",
        {
                { "Amphion",            specs+23, N_B,  8, 50, 4, 0 },
                { "Active",             specs+24, N_B,  6, 48, 4, 0 },
        {
                { "Amphion",            specs+23, N_B,  8, 50, 4, 0 },
                { "Active",             specs+24, N_B,  6, 48, 4, 0 },
@@ -91,27 +88,27 @@ struct scenario scene[] = {
                { "Corona",             specs+29, N_F, 12, 31, 2, 0 },
                { "Carolina",           specs+30, N_F, 15, 28, 2, 0 }
        },
                { "Corona",             specs+29, N_F, 12, 31, 2, 0 },
                { "Carolina",           specs+30, N_F, 15, 28, 2, 0 }
        },
-       2, 5, 6, 0, 1, 0, 2, "Constitution vs. Guerriere",
+       2, 5, 6, 2, "Constitution vs. Guerriere",
        {
                { "Constitution",       specs+31, N_A,  7, 35, 1, 0 },
                { "Guerriere",          specs+32, N_B,  7, 47, 4, 0 }
        },
        {
                { "Constitution",       specs+31, N_A,  7, 35, 1, 0 },
                { "Guerriere",          specs+32, N_B,  7, 47, 4, 0 }
        },
-       1, 3, 5, 0, 1, 0, 2, "United States vs. Macedonian",
+       1, 3, 5, 2, "United States vs. Macedonian",
        {
                { "United States",      specs+33, N_A,  1, 52, 6, 0 },
                { "Macedonian",         specs+34, N_B, 14, 40, 1, 0 }
        },
        {
                { "United States",      specs+33, N_A,  1, 52, 6, 0 },
                { "Macedonian",         specs+34, N_B, 14, 40, 1, 0 }
        },
-       1, 3, 6, 0, 1, 0, 2, "Constitution vs. Java",
+       1, 3, 6, 2, "Constitution vs. Java",
        {
                { "Constitution",       specs+31, N_A,  1, 40, 2, 0 },
                { "Java",               specs+35, N_B, 11, 40, 2, 0 }
        },
        {
                { "Constitution",       specs+31, N_A,  1, 40, 2, 0 },
                { "Java",               specs+35, N_B, 11, 40, 2, 0 }
        },
-       1, 3, 5, 0, 1, 0, 2, "Chesapeake vs. Shannon",
+       1, 3, 5, 2, "Chesapeake vs. Shannon",
        {
                { "Chesapeake",         specs+36, N_A, 13, 40, 2, 0 },
                { "Shannon",            specs+37, N_B,  1, 42, 2, 0 }
        },
        {
                { "Chesapeake",         specs+36, N_A, 13, 40, 2, 0 },
                { "Shannon",            specs+37, N_B,  1, 42, 2, 0 }
        },
-       1, 1, 6, 0, 1, 0, 5, "The Battle of Lake Erie",
+       1, 1, 6, 5, "The Battle of Lake Erie",
        {
                { "Lawrence",           specs+38, N_A,  4, 55, 8, 0 },
                { "Niagara",            specs+42, N_A,  7, 61, 8, 0 },
        {
                { "Lawrence",           specs+38, N_A,  4, 55, 8, 0 },
                { "Niagara",            specs+42, N_A,  7, 61, 8, 0 },
@@ -119,24 +116,24 @@ struct scenario scene[] = {
                { "Detroit",            specs+40, N_B,  7, 22, 2, 0 },
                { "Q. Charlotte",       specs+41, N_B, 10, 19, 2, 0 }
        },
                { "Detroit",            specs+40, N_B,  7, 22, 2, 0 },
                { "Q. Charlotte",       specs+41, N_B, 10, 19, 2, 0 }
        },
-       1, 1, 5, 0, 1, 0, 2, "Wasp vs. Reindeer",
+       1, 1, 5, 2, "Wasp vs. Reindeer",
        {
                { "Wasp",               specs+42, N_A,  3, 41, 2, 0 },
                { "Reindeer",           specs+43, N_B, 10, 48, 2, 0 }
        },
        {
                { "Wasp",               specs+42, N_A,  3, 41, 2, 0 },
                { "Reindeer",           specs+43, N_B, 10, 48, 2, 0 }
        },
-       1, 2, 5, 0, 1, 0, 3, "Constitution vs. Cyane and Levant",
+       1, 2, 5, 3, "Constitution vs. Cyane and Levant",
        {
                { "Constitution",       specs+31, N_A, 10, 45, 2, 0 },
                { "Cyane",              specs+44, N_B,  3, 37, 2, 0 },
                { "Levant",             specs+45, N_B,  5, 35, 2, 0 }
        },
        {
                { "Constitution",       specs+31, N_A, 10, 45, 2, 0 },
                { "Cyane",              specs+44, N_B,  3, 37, 2, 0 },
                { "Levant",             specs+45, N_B,  5, 35, 2, 0 }
        },
-       5, 5, 5, 0, 1, 0, 3, "Pellew vs. Droits de L'Homme",
+       5, 5, 5, 3, "Pellew vs. Droits de L'Homme",
        {
                { "Indefatigable",      specs+46, N_B, 12, 45, 6, 0 },
                { "Amazon",             specs+47, N_B,  9, 48, 6, 0 },
                { "Droits L'Hom",       specs+48, N_F,  3, 28, 5, 0 }
        },
        {
                { "Indefatigable",      specs+46, N_B, 12, 45, 6, 0 },
                { "Amazon",             specs+47, N_B,  9, 48, 6, 0 },
                { "Droits L'Hom",       specs+48, N_F,  3, 28, 5, 0 }
        },
-       2, 2, 3, 0, 1, 0, 10, "Algeciras",
+       2, 2, 3, 10, "Algeciras",
        {
                { "Caesar",             specs+49, N_B,  7, 70, 6, 0 },
                { "Pompee",             specs+50, N_B,  5, 72, 6, 0 },
        {
                { "Caesar",             specs+49, N_B,  7, 70, 6, 0 },
                { "Pompee",             specs+50, N_B,  5, 72, 6, 0 },
@@ -149,7 +146,7 @@ struct scenario scene[] = {
                { "Indomptable",        specs+51, N_F,  7, 23, 5, 0 },
                { "Desaix",             specs+52, N_F,  7, 27, 7, 0 }
        },
                { "Indomptable",        specs+51, N_F,  7, 23, 5, 0 },
                { "Desaix",             specs+52, N_F,  7, 27, 7, 0 }
        },
-       5, 3, 6, 0, 1, 0, 7, "Lake Champlain",
+       5, 3, 6, 7, "Lake Champlain",
        {
                { "Saratoga",           specs+60, N_A,  8, 10, 1, 0 },
                { "Eagle",              specs+61, N_A,  9, 13, 2, 0 },
        {
                { "Saratoga",           specs+60, N_A,  8, 10, 1, 0 },
                { "Eagle",              specs+61, N_A,  9, 13, 2, 0 },
@@ -159,31 +156,31 @@ struct scenario scene[] = {
                { "Linnet",             specs+58, N_B,  7, 68, 6, 0 },
                { "Chubb",              specs+59, N_B, 10, 65, 6, 0 }
        },
                { "Linnet",             specs+58, N_B,  7, 68, 6, 0 },
                { "Chubb",              specs+59, N_B, 10, 65, 6, 0 }
        },
-       5, 3, 6, 0, 1, 0, 4, "Last Voyage of the USS President",
+       5, 3, 6, 4, "Last Voyage of the USS President",
        {
                { "President",          specs+67, N_A, 12, 42, 5, 0 },
                { "Endymion",           specs+64, N_B,  5, 42, 5, 0 },
                { "Pomone",             specs+65, N_B,  7, 82, 6, 0 },
                { "Tenedos",            specs+66, N_B,  7, -1, 4, 0 }
        },
        {
                { "President",          specs+67, N_A, 12, 42, 5, 0 },
                { "Endymion",           specs+64, N_B,  5, 42, 5, 0 },
                { "Pomone",             specs+65, N_B,  7, 82, 6, 0 },
                { "Tenedos",            specs+66, N_B,  7, -1, 4, 0 }
        },
-       7, 5, 5, 0, 1, 0, 2, "Hornblower and the Natividad",
+       7, 5, 5, 2, "Hornblower and the Natividad",
        {
                { "Lydia",              specs+68, N_B, 12, 40, 2, 0 },
                { "Natividad",          specs+69, N_S,  2, 40, 4, 0 }
        },
        {
                { "Lydia",              specs+68, N_B, 12, 40, 2, 0 },
                { "Natividad",          specs+69, N_S,  2, 40, 4, 0 }
        },
-       1, 3, 6, 0, 1, 0, 2, "Curse of the Flying Dutchman",
+       1, 3, 6, 2, "Curse of the Flying Dutchman",
        {
                { "Piece of Cake",      specs+19, N_S,  7, 40, 2, 0 },
                { "Flying Dutchy",      specs+71, N_F,  7, 41, 1, 0 }
        },
        {
                { "Piece of Cake",      specs+19, N_S,  7, 40, 2, 0 },
                { "Flying Dutchy",      specs+71, N_F,  7, 41, 1, 0 }
        },
-       1, 4, 1, 0, 1, 0, 4, "The South Pacific",
+       1, 4, 1, 4, "The South Pacific",
        {
                { "USS Scurvy",         specs+70, N_A,  7, 40, 1, 0 },
                { "HMS Tahiti",         specs+71, N_B, 12, 60, 1, 0 },
                { "Australian",         specs+18, N_S,  5, 20, 8, 0 },
                { "Bikini Atoll",       specs+63, N_F,  2, 60, 4, 0 }
        },
        {
                { "USS Scurvy",         specs+70, N_A,  7, 40, 1, 0 },
                { "HMS Tahiti",         specs+71, N_B, 12, 60, 1, 0 },
                { "Australian",         specs+18, N_S,  5, 20, 8, 0 },
                { "Bikini Atoll",       specs+63, N_F,  2, 60, 4, 0 }
        },
-       7, 3, 6, 0, 1, 0, 5, "Hornblower and the battle of Rosas bay",
+       7, 3, 6, 5, "Hornblower and the battle of Rosas bay",
        {
                { "Sutherland",         specs+5,  N_B, 13, 30, 2, 0 },
                { "Turenne",            specs+10, N_F,  9, 35, 6, 0 },
        {
                { "Sutherland",         specs+5,  N_B, 13, 30, 2, 0 },
                { "Turenne",            specs+10, N_F,  9, 35, 6, 0 },
@@ -191,7 +188,7 @@ struct scenario scene[] = {
                { "Paris",              specs+53, N_F,  3, 45, 4, 0 },
                { "Napolean",           specs+56, N_F,  1, 40, 6, 0 }
        },
                { "Paris",              specs+53, N_F,  3, 45, 4, 0 },
                { "Napolean",           specs+56, N_F,  1, 40, 6, 0 }
        },
-       6, 4, 7, 0, 1, 0, 5, "Cape Horn",
+       6, 4, 7, 5, "Cape Horn",
        {
                { "Concord",            specs+51, N_A,  3, 20, 4, 0 },
                { "Berkeley",           specs+7,  N_A,  5, 50, 5, 0 },
        {
                { "Concord",            specs+51, N_A,  3, 20, 4, 0 },
                { "Berkeley",           specs+7,  N_A,  5, 50, 5, 0 },
@@ -199,32 +196,32 @@ struct scenario scene[] = {
                { "Madrid",             specs+53, N_S, 13, 60, 8, 0 },
                { "Musket",             specs+10, N_F, 10, 60, 7, 0 }
        },
                { "Madrid",             specs+53, N_S, 13, 60, 8, 0 },
                { "Musket",             specs+10, N_F, 10, 60, 7, 0 }
        },
-       8, 3, 7, 0, 1, 0, 3, "New Orleans",
+       8, 3, 7, 3, "New Orleans",
        {
                { "Alligator",          specs+71, N_A, 13,  5, 1, 0 },
                { "Firefly",            specs+50, N_B, 10, 20, 8, 0 },
                { "Cypress",            specs+46, N_B,  5, 10, 6, 0 }
        },
        {
                { "Alligator",          specs+71, N_A, 13,  5, 1, 0 },
                { "Firefly",            specs+50, N_B, 10, 20, 8, 0 },
                { "Cypress",            specs+46, N_B,  5, 10, 6, 0 }
        },
-       5, 3, 7, 0, 1, 0, 3, "Botany Bay",
+       5, 3, 7, 3, "Botany Bay",
        {
                { "Shark",              specs+11, N_B,  6, 15, 4, 0 },
                { "Coral Snake",        specs+31, N_F,  3, 30, 6, 0 },
                { "Sea Lion",           specs+33, N_F, 13, 50, 8, 0 }
        },
        {
                { "Shark",              specs+11, N_B,  6, 15, 4, 0 },
                { "Coral Snake",        specs+31, N_F,  3, 30, 6, 0 },
                { "Sea Lion",           specs+33, N_F, 13, 50, 8, 0 }
        },
-       4, 3, 6, 0, 1, 0, 4, "Voyage to the Bottom of the Sea",
+       4, 3, 6, 4, "Voyage to the Bottom of the Sea",
        {
                { "Seaview",            specs+71, N_A,  6, 3,  3, 0 },
                { "Flying Sub",         specs+64, N_A,  8, 3,  3, 0 },
                { "Mermaid",            specs+70, N_B,  2, 5,  5, 0 },
                { "Giant Squid",        specs+53, N_S, 10, 30, 8, 0 }
        },
        {
                { "Seaview",            specs+71, N_A,  6, 3,  3, 0 },
                { "Flying Sub",         specs+64, N_A,  8, 3,  3, 0 },
                { "Mermaid",            specs+70, N_B,  2, 5,  5, 0 },
                { "Giant Squid",        specs+53, N_S, 10, 30, 8, 0 }
        },
-       7, 3, 6, 0, 1, 0, 3, "Frigate Action",
+       7, 3, 6, 3, "Frigate Action",
        {
                { "Killdeer",           specs+21, N_A,  7, 20, 8, 0 },
                { "Sandpiper",          specs+27, N_B,  5, 40, 8, 0 },
                { "Curlew",             specs+34, N_S, 10, 60, 8, 0 }
        },
        {
                { "Killdeer",           specs+21, N_A,  7, 20, 8, 0 },
                { "Sandpiper",          specs+27, N_B,  5, 40, 8, 0 },
                { "Curlew",             specs+34, N_S, 10, 60, 8, 0 }
        },
-       7, 2, 5, 0, 1, 0, 6, "The Battle of Midway",
+       7, 2, 5, 6, "The Battle of Midway",
        {
                { "Enterprise",         specs+49, N_A, 10, 70, 8, 0 },
                { "Yorktown",           specs+51, N_A,  3, 70, 7, 0 },
        {
                { "Enterprise",         specs+49, N_A, 10, 70, 8, 0 },
                { "Yorktown",           specs+51, N_A,  3, 70, 7, 0 },
@@ -234,7 +231,7 @@ struct scenario scene[] = {
                { "Soryu",              specs+55, N_J,  2, 14, 4, 0 }
        },
        /*
                { "Soryu",              specs+55, N_J,  2, 14, 4, 0 }
        },
        /*
-       4, 3, 4, 0, 1, 0, 8, "Star Trek",
+       4, 3, 4, 8, "Star Trek",
        {
                { "Enterprise",         specs+72, N_A, 20,  4, 2, 0 },
                { "Yorktown",           specs+72, N_A, 19,  2, 2, 0 },
        {
                { "Enterprise",         specs+72, N_A, 20,  4, 2, 0 },
                { "Yorktown",           specs+72, N_A, 19,  2, 2, 0 },
@@ -248,7 +245,6 @@ struct scenario scene[] = {
        */
 };
 
        */
 };
 
-/* happy */
 struct shipspecs specs[] = {
 /*      bs fs ta guns   hull  crew1   crew3    gunR  carR   rig2  rig4 pts */
 /*                 class   qual   crew2    gunL   carL   rig1  rig3        */
 struct shipspecs specs[] = {
 /*      bs fs ta guns   hull  crew1   crew3    gunR  carR   rig2  rig4 pts */
 /*                 class   qual   crew2    gunL   carL   rig1  rig3        */
index 2564af4..cfeaed6 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)misc.c      1.2 83/07/20";
+static char *sccsid = "@(#)misc.c      1.3 83/10/10";
 #endif
 #include "externs.h"
 
 #endif
 #include "externs.h"
 
@@ -14,7 +14,7 @@ struct ship *from, *to;
        register int bb, bs, sb, ss, result;
 
        if (!to->file->dir)
        register int bb, bs, sb, ss, result;
 
        if (!to->file->dir)
-               return 30000;
+               return -1;
        stern1r = bow1r = from->file->row;
        stern1c = bow1c = from->file->col;
        stern2r = bow2r = to->file->row;
        stern1r = bow1r = from->file->row;
        stern1c = bow1c = from->file->col;
        stern2r = bow2r = to->file->row;
@@ -61,3 +61,137 @@ char side, anyship;
        }
        return closest;
 }
        }
        return closest;
 }
+
+angle(dr, dc)
+register dr, dc;
+{
+       register i;
+
+       if (dc >= 0 && dr > 0)
+               i = 0;
+       else if (dr <= 0 && dc > 0)
+               i = 2;
+       else if (dc <= 0 && dr < 0)
+               i = 4;
+       else
+               i = 6;
+       dr = abs(dr);
+       dc = abs(dc);
+       if ((i == 0 || i == 4) && dc * 2.4 > dr) {
+               i++;
+               if (dc > dr * 2.4)
+                       i++;
+       } else if ((i == 2 || i == 6) && dr * 2.4 > dc) {
+               i++;
+               if (dr > dc * 2.4)
+                       i++;
+       }
+       return i % 8 + 1;
+}
+
+gunsbear(from, to)             /* checks for target bow or stern */
+register struct ship *from, *to;
+{
+       int Dr, Dc, i;
+       register ang;
+
+       Dr = from->file->row - to->file->row;
+       Dc = to->file->col - from->file->col;
+       for (i = 2; i; i--) {
+               if ((ang = angle(Dr, Dc) - from->file->dir + 1) < 1)
+                       ang += 8;
+               if (ang >= 2 && ang <= 4)
+                       return 'r';
+               if (ang >= 6 && ang <= 7)
+                       return 'l';
+               Dr += dr[to->file->dir];
+               Dc += dc[to->file->dir];
+       }
+       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;
+
+       Dr = from->file->row - on->file->row;
+       Dc = on->file->col - from->file->col;
+       if (quick == -1) {
+               Dr += dr[on->file->dir];
+               Dc += dc[on->file->dir];
+       }
+       ang = angle(Dr, Dc);
+       if (quick != 0)
+               return ang;
+       ang = (ang + 4 - on->file->dir - 1) % 8 + 1;
+       return ang < 5;
+}
+
+rmend(str)
+char *str;
+{
+       register char *p;
+
+       for (p = str; *p; p++)
+               ;
+       if (p != str)
+               *--p = 0;
+}
+
+colours(sp)
+register struct ship *sp;
+{
+       register char flag;
+
+       if (sp->file->struck)
+               flag = '!';
+       if (sp->file->explode)
+               flag = '#';
+       if (sp->file->sink)
+               flag = '~';
+       if (sp->file->struck)
+               return flag;
+       flag = *countryname[capship(sp)->nationality];
+       return sp->file->FS ? flag : tolower(flag);
+}
+
+#ifdef notdef
+#define PI 3.1415926535
+
+float contable[8] =
+       { 1.5708, 0.7854, 0.0, -0.7854, -1.5708, -2.3562, -PI, 2.3562 };
+
+int tantable[40] = {
+       0,100,197,291,381,
+       464,540,610,675,733,
+       785,833,876,915,951,
+       983,1012,1039,1064,1086,
+       1107,1126,1144,1161,1176,
+       1190,1204,1216,1227,1239,
+       1249,1259,1268,1277,1285,
+       1293,1300,1307,1313,1470
+};
+
+double
+arctan(y,x)
+int y,x;
+{
+       int sx, sy;
+       register int index;
+
+       sy = y < 0 ? -1 : 1;
+       sx = x < 0 ? -1 : 1;
+       y *= sy;
+       x *= sx;
+       if (!x)
+               return (double) PI/2 * sy;
+       index = 10 * y / x + 0.5;
+       if (index > 39)
+               index = 39;
+       return (double)
+               sy * (sx < 0 ? PI : 0 + sx*((float)tantable[index]/1000));
+}
+#endif
index 6dff455..3675588 100644 (file)
@@ -1,10 +1,10 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)pl_1.c      1.9 83/07/20";
+static char *sccsid = "@(#)pl_1.c      1.10 83/10/10";
 #endif
 
 #include "player.h"
 #include <sys/types.h>
 #endif
 
 #include "player.h"
 #include <sys/types.h>
-#include <wait.h>
+#include <sys/wait.h>
 
 int choke(), child();
 
 
 int choke(), child();
 
@@ -14,8 +14,9 @@ int argc;
 char **argv;
 {
        register struct ship *sp;
 char **argv;
 {
        register struct ship *sp;
-       int aheadfirst, ma;
        int ta;
        int ta;
+       char aheadfirst;
+       int ma;
        char nodrive = 0, randomize = 0, debug = 0;
        char *badstring();
        extern char _sobuf[];
        char nodrive = 0, randomize = 0, debug = 0;
        char *badstring();
        extern char _sobuf[];
@@ -49,10 +50,8 @@ char **argv;
                case 'm':
                        if (mc->crew3 && !snagged(ms)
                            && windspeed != 0) {
                case 'm':
                        if (mc->crew3 && !snagged(ms)
                            && windspeed != 0) {
-                               ta = maxturns(ms);
-                               aheadfirst = ta & 0100000;
+                               ta = maxturns(ms, &aheadfirst);
                                ma = maxmove(ms, mf->dir, 0);
                                ma = maxmove(ms, mf->dir, 0);
-                               ta &= 077777;
                                acceptmove(ma, ta, aheadfirst);
                        } else
                                Signal("Unable to move", (struct ship *)0);
                                acceptmove(ma, ta, aheadfirst);
                        } else
                                Signal("Unable to move", (struct ship *)0);
@@ -152,10 +151,10 @@ char randomize, nodriver, debug;
 {
        register struct File *fp;
        register struct ship *sp;
 {
        register struct File *fp;
        register struct ship *sp;
-       char captain[80], file[25];
+       char captain[80];
        char message[60];
        int load;
        char message[60];
        int load;
-       int people = 0;
+       int active;
        register int n;
        char *nameptr;
        int nat[NNATION];
        register int n;
        char *nameptr;
        int nat[NNATION];
@@ -166,13 +165,10 @@ char randomize, nodriver, debug;
                (void) puts("Choose a scenario:\n");
                (void) puts("\n\tNUMBER\tSHIPS\tIN PLAY\tTITLE");
                for (n = 0; n < NSCENE; n++) {
                (void) puts("Choose a scenario:\n");
                (void) puts("\n\tNUMBER\tSHIPS\tIN PLAY\tTITLE");
                for (n = 0; n < NSCENE; n++) {
-                       printf("\t%d):\t%d", n, scene[n].vessels);
-                       (void) sprintf(file, "/tmp/.%d", n);
-                       if (access(file, 0) >= 0)
-                               printf("\tYES");
-                       else
-                               printf("\tno");
-                       printf("\t%s\n", scene[n].name);
+                       /* ( */
+                       printf("\t%d):\t%d\t%s\t%s\n", n, scene[n].vessels,
+                               sync_exists(n) ? "YES" : "no",
+                               scene[n].name);
                }
 reprint:
                printf("\nScenario number? ");
                }
 reprint:
                printf("\nScenario number? ");
@@ -188,21 +184,11 @@ reprint:
        cc = &scene[game];
        ls = cc->ship + cc->vessels;
 
        cc = &scene[game];
        ls = cc->ship + cc->vessels;
 
-       (void) sprintf(file, "/tmp/.%d", game);
-       if (access(file, 0) < 0) {
-               int omask;
-#ifdef SETUID
-               omask = umask(077);
-#else
-               omask = umask(011);
-#endif
-               syncfile = fopen(file, "w+");
-               (void) umask(omask);
-       } else {
-               syncfile = fopen(file, "r+");
-               people = 1;
+       active = sync_exists(game);
+       if (sync_open() < 0) {
+               perror("sail: syncfile");
+               exit(1);
        }
        }
-       lastsync = 0;
 
        for (n = 0; n < NNATION; n++)
                nat[n] = 0;
 
        for (n = 0; n < NNATION; n++)
                nat[n] = 0;
@@ -214,54 +200,56 @@ reprint:
                }
                sp->file->stern = nat[sp->nationality]++;
        }
                }
                sp->file->stern = nat[sp->nationality]++;
        }
-       if (people > 0) {
+
+       if (active) {
                (void) puts("Synchronizing with the other players...");
                (void) fflush(stdout);
                Sync();
                (void) puts("Synchronizing with the other players...");
                (void) fflush(stdout);
                Sync();
-               foreachship(sp) {
-                       if (sp->file->captain[0]
-                           || sp->file->struck || sp->file->captured != 0)
+       }
+       for (;;) {
+               foreachship(sp)
+                       if (sp->file->captain[0] == 0 && !sp->file->struck
+                           && sp->file->captured == 0)
                                break;
                                break;
-               }
                if (sp >= ls) {
                        (void) puts("All ships taken in that scenario.");
                        foreachship(sp)
                                free((char *)sp->file);
                if (sp >= ls) {
                        (void) puts("All ships taken in that scenario.");
                        foreachship(sp)
                                free((char *)sp->file);
+                       sync_close(0);
                        people = 0;
                        people = 0;
-                       (void) fclose(syncfile);
                        goto reprint;
                }
                        goto reprint;
                }
-               player = sp - cc->ship;
-       } else
-               player = 0;
-
-       while (randomize) {
-               printf("%s\n\n", cc->name);
-               foreachship(sp) {
-                       printf("  %2d:  %-10s %-15s  (%-2d pts)   %s\n",
-                               sp - SHIP(0),
-                               countryname[sp->nationality],
-                               sp->shipname,
-                               sp->specs->pts,
-                               saywhat(sp, 1));
-               }
-               printf("\nWhich ship do you want (0-%d)? ", cc->vessels-1);
-               (void) fflush(stdout);
-               if (scanf("%d", &player) != 1 || player < 0
-                   || player >= cc->vessels) {
-                       while (getchar() != '\n')
-                               ;
-                       (void) puts("Say what?");
+               if (!randomize) {
+                       player = sp - cc->ship;
                } else {
                } else {
-                       while (getchar() != '\n')
-                               ;
-                       Sync();
-                       fp = SHIP(player)->file;
-                       if (fp->captain[0] || fp->struck || fp->captured != 0)
-                               (void) puts("Sorry, that ship is taken.");
-                       else
-                               break;
+                       printf("%s\n\n", cc->name);
+                       foreachship(sp)
+                               printf("  %2d:  %-10s %-15s  (%-2d pts)   %s\n",
+                                       sp - SHIP(0),
+                                       countryname[sp->nationality],
+                                       sp->shipname,
+                                       sp->specs->pts,
+                                       saywhat(sp, 1));
+                       printf("\nWhich ship (0-%d)? ", cc->vessels-1);
+                       (void) fflush(stdout);
+                       if (scanf("%d", &player) != 1 || player < 0
+                           || player >= cc->vessels) {
+                               while (getchar() != '\n')
+                                       ;
+                               (void) puts("Say what?");
+                               player = -1;
+                       } else
+                               while (getchar() != '\n')
+                                       ;
                }
                }
+               if (player < 0)
+                       continue;
+               Sync();
+               fp = SHIP(player)->file;
+               if (fp->captain[0] || fp->struck || fp->captured != 0)
+                       (void) puts("That ship is taken.");
+               else
+                       break;
        }
 
        ms = SHIP(player);
        }
 
        ms = SHIP(player);
@@ -273,9 +261,7 @@ reprint:
        (void) signal(SIGQUIT, choke);
        (void) signal(SIGCHLD, child);
 
        (void) signal(SIGQUIT, choke);
        (void) signal(SIGCHLD, child);
 
-       Write(W_CAPTAIN, ms, 1, (int) "begin", 0, 0, 0);
-       if (people)
-               Write(W_PEOPLE, SHIP(0), 0, cc->people + 1, 0, 0, 0);
+       Write(W_BEGIN, ms, 0, 0, 0, 0, 0);
        Sync();
        printf("Your ship is the %s, a %d gun %s (%s crew).\n",
                ms->shipname, mc->guns, classname[mc->class],
        Sync();
        printf("Your ship is the %s, a %d gun %s (%s crew).\n",
                ms->shipname, mc->guns, classname[mc->class],
@@ -290,12 +276,15 @@ reprint:
                        (void) strcpy(captain, "no name");
        }
        captain[sizeof captain - 1] = '\0';
                        (void) strcpy(captain, "no name");
        }
        captain[sizeof captain - 1] = '\0';
+       Write(W_CAPTAIN, ms, 1, (int)captain, 0, 0, 0);
        for (n = 0; n < 2; n++) {
        for (n = 0; n < 2; n++) {
+               char buf[10];
+
                printf("\nInitial broadside %s (grape, chain, round, double): ",
                        n ? "right" : "left");
                (void) fflush(stdout);
                printf("\nInitial broadside %s (grape, chain, round, double): ",
                        n ? "right" : "left");
                (void) fflush(stdout);
-               (void) scanf("%s", file);
-               switch (*file) {
+               (void) scanf("%s", buf);
+               switch (*buf) {
                case 'g':
                        load = L_GRAPE;
                        break;
                case 'g':
                        load = L_GRAPE;
                        break;
@@ -319,8 +308,7 @@ reprint:
                        mf->readyL = R_LOADED|R_INITIAL;
                }
        }
                        mf->readyL = R_LOADED|R_INITIAL;
                }
        }
-       Write(W_CAPTAIN, ms, 1, (int)captain, 0, 0, 0);
-       if (!people && !nodriver) {
+       if (!active && !nodriver) {
                char num[10];
                (void) sprintf(num, "%d", game);
                if (!fork()) {
                char num[10];
                (void) sprintf(num, "%d", game);
                if (!fork()) {
@@ -333,6 +321,14 @@ reprint:
                }
        }
 
                }
        }
 
+       foreachship(sp) {
+               sp->file->dir = sp->shipdir;
+               sp->file->row = sp->shiprow;
+               sp->file->col = sp->shipcol;
+       }
+       windspeed = cc->windspeed;
+       winddir = cc->winddir;
+
        initscreen();
 
        board();
        initscreen();
 
        board();
@@ -348,7 +344,6 @@ int conditions;
        FILE *fp;
        int people;
        float net;
        FILE *fp;
        int people;
        float net;
-       char * capn;
        char message[60];
        register int n;
        struct logs log[10], temp;
        char message[60];
        register int n;
        struct logs log[10], temp;
@@ -360,9 +355,10 @@ int conditions;
        (void) signal(SIGCHLD, SIG_IGN);
 
        if (conditions != -1) {
        (void) signal(SIGCHLD, SIG_IGN);
 
        if (conditions != -1) {
-               capn = mf->captain;
-               (void) sprintf(message,"Captain %s relinquishing.",capn);
+               (void) sprintf(message,"Captain %s relinquishing.",
+                       mf->captain);
                Write(W_SIGNAL, ms, 1, (int)message, 0, 0, 0);
                Write(W_SIGNAL, ms, 1, (int)message, 0, 0, 0);
+               Write(W_END, ms, 0, 0, 0, 0, 0);
 
                if (fp = fopen(LOGFILE, "r+")) {
                        net = (float)mf->points / mc->pts;
 
                if (fp = fopen(LOGFILE, "r+")) {
                        net = (float)mf->points / mc->pts;
@@ -383,7 +379,7 @@ int conditions;
                                if (net > (float) log[n].l_netpoints / scene[log[n].l_gamenum].ship[log[n].l_shipnum].specs->pts) {
                                        (void) fwrite((char *)log,
                                                sizeof (struct logs), n, fp);
                                if (net > (float) log[n].l_netpoints / scene[log[n].l_gamenum].ship[log[n].l_shipnum].specs->pts) {
                                        (void) fwrite((char *)log,
                                                sizeof (struct logs), n, fp);
-                                       (void) strcpy(temp.l_name, capn);
+                                       (void) strcpy(temp.l_name, mf->captain);
                                        temp.l_uid = getuid();
                                        temp.l_shipnum = player;
                                        temp.l_gamenum = game;
                                        temp.l_uid = getuid();
                                        temp.l_shipnum = player;
                                        temp.l_gamenum = game;
@@ -396,8 +392,6 @@ int conditions;
                                }
                        (void) fclose(fp);
                }
                                }
                        (void) fclose(fp);
                }
-               Write(W_CAPTAIN, ms, 1, (int)" ", 0, 0, 0);
-               Write(W_PEOPLE, SHIP(0), 0, cc->people - 1, 0, 0, 0);
                if (done_curses) {
                        screen();
                        Signal("It looks like you've had it!",
                if (done_curses) {
                        screen();
                        Signal("It looks like you've had it!",
@@ -426,7 +420,7 @@ int conditions;
                        else
                                printf("leave: unknown code %d\n", conditions);
                }
                        else
                                printf("leave: unknown code %d\n", conditions);
                }
-               (void) fclose(syncfile);
+               Sync();
        }
        if (done_curses) {
                lastline();
        }
        if (done_curses) {
                lastline();
index 3a354a5..ccc8a51 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)pl_2.c      1.4 83/10/05";
+static char *sccsid = "@(#)pl_2.c      1.5 83/10/10";
 #endif
 
 #include "player.h"
 #endif
 
 #include "player.h"
@@ -127,11 +127,11 @@ doboarding()
        crew[0] = mc->crew1;
        crew[1] = mc->crew2;
        crew[2] = mc->crew3;
        crew[0] = mc->crew1;
        crew[1] = mc->crew2;
        crew[2] = mc->crew3;
-       for (n=0; n < 3; n++) {
+       for (n = 0; n < NBP; n++) {
                if (mf->OBP[n].turnsent)
                            men += mf->OBP[n].turnsent;
        }
                if (mf->OBP[n].turnsent)
                            men += mf->OBP[n].turnsent;
        }
-       for (n=0; n < 3; n++) {
+       for (n = 0; n < NBP; n++) {
                if (mf->DBP[n].turnsent)
                            men += mf->DBP[n].turnsent;
        }
                if (mf->DBP[n].turnsent)
                            men += mf->DBP[n].turnsent;
        }
@@ -145,14 +145,14 @@ doboarding()
                crew[2] = crew[2] != 0;
        }
        foreachship(sp) {
                crew[2] = crew[2] != 0;
        }
        foreachship(sp) {
-               if (sp == ms || sp->file->dir == 0 || range(ms, sp) > 0)
+               if (sp == ms || sp->file->dir == 0 || range(ms, sp) > 1)
                        continue;
                if (ms->nationality == capship(sp)->nationality)
                        continue;
                if (meleeing(ms, sp) && crew[2]) {
                        Signal("How many more to board the %s (%c%c)? ", sp);
                        parties(crew, sp, 0);
                        continue;
                if (ms->nationality == capship(sp)->nationality)
                        continue;
                if (meleeing(ms, sp) && crew[2]) {
                        Signal("How many more to board the %s (%c%c)? ", sp);
                        parties(crew, sp, 0);
-               } else if (grappled2(ms, sp) && crew[2]) {
+               } else if ((fouled2(ms, sp) || grappled2(ms, sp)) && crew[2]) {
                        Signal("Crew sections to board the %s (%c%c) (3 max) ?",
                                sp);
                        parties(crew, sp, 0);
                        Signal("Crew sections to board the %s (%c%c) (3 max) ?",
                                sp);
                        parties(crew, sp, 0);
index a6ca8c7..7d41b34 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)pl_3.c      1.1 83/07/20";
+static char *sccsid = "@(#)pl_3.c      1.2 83/10/10";
 #endif
 
 #include "player.h"
 #endif
 
 #include "player.h"
@@ -299,7 +299,7 @@ register struct ship *ship;
 
        if (ship == 0)
                Signal("No more ships left.", (struct ship *)0);
 
        if (ship == 0)
                Signal("No more ships left.", (struct ship *)0);
-       else if (ship->shipdir) {
+       else if (ship->file->dir != 0) {
                Signal("Sail ho! (range %d, %s)",
                        (struct ship *)0, range(ms, ship), saywhat(ship, 0));
                i = portside(ms, ship, 1) - mf->dir;
                Signal("Sail ho! (range %d, %s)",
                        (struct ship *)0, range(ms, ship), saywhat(ship, 0));
                i = portside(ms, ship, 1) - mf->dir;
index ee405cc..d3aa4fa 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)pl_4.c      1.2 83/10/05";
+static char *sccsid = "@(#)pl_4.c      1.3 83/10/10";
 #endif
 
 #include "player.h"
 #endif
 
 #include "player.h"
@@ -154,6 +154,7 @@ char *buf;
 newturn()
 {
        repaired = loaded = fired = changed = 0;
 newturn()
 {
        repaired = loaded = fired = changed = 0;
+       movebuf[0] = '\0';
 
        (void) alarm(0);
        if (mf->readyL & R_LOADING)
 
        (void) alarm(0);
        if (mf->readyL & R_LOADING)
@@ -166,16 +167,11 @@ newturn()
                        mf->readyR = R_LOADING;
                else
                        mf->readyR = R_LOADED;
                        mf->readyR = R_LOADING;
                else
                        mf->readyR = R_LOADED;
-       movebuf[0] = '\0';
        Sync();
        if (turn % 50 == 0)             /* still playing */
        Sync();
        if (turn % 50 == 0)             /* still playing */
-               Write(W_TIME, SHIP(0), 0, 1, 0, 0, 0); /* XXX */
-       windspeed = cc->windspeed;
-       winddir = cc->winddir;
-       turn = cc->turn;
+               Write(W_ALIVE, SHIP(0), 0, 0, 0, 0, 0); /* XXX */
        if (mf->FS == 1)
                Write(W_FS, ms, 0, 2, 0, 0, 0);
        if (mf->FS == 1)
                Write(W_FS, ms, 0, 2, 0, 0, 0);
-       readpos();
        adjustview();
 
        screen();
        adjustview();
 
        screen();