new grapple and foul data structure.
authorEdward Wang <edward@ucbvax.Berkeley.EDU>
Sun, 18 Dec 1983 04:39:19 +0000 (20:39 -0800)
committerEdward Wang <edward@ucbvax.Berkeley.EDU>
Sun, 18 Dec 1983 04:39:19 +0000 (20:39 -0800)
SCCS-vsn: games/sail/dr_1.c 2.6
SCCS-vsn: games/sail/assorted.c 2.3
SCCS-vsn: games/sail/dr_2.c 2.4
SCCS-vsn: games/sail/dr_3.c 2.4
SCCS-vsn: games/sail/extern.h 2.3
SCCS-vsn: games/sail/dr_4.c 2.2
SCCS-vsn: games/sail/player.h 2.5
SCCS-vsn: games/sail/parties.c 2.2
SCCS-vsn: games/sail/pl_1.c 2.5
SCCS-vsn: games/sail/pl_3.c 2.3
SCCS-vsn: games/sail/sync.c 2.3

usr/src/games/sail/assorted.c
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/dr_4.c
usr/src/games/sail/extern.h
usr/src/games/sail/parties.c
usr/src/games/sail/pl_1.c
usr/src/games/sail/pl_3.c
usr/src/games/sail/player.h
usr/src/games/sail/sync.c

index 7c1acd5..b29f549 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)assorted.c  2.2 83/11/01";
+static char *sccsid = "@(#)assorted.c  2.3 83/12/17";
 #endif
 
 #include "externs.h"
 #endif
 
 #include "externs.h"
@@ -179,7 +179,7 @@ int rig, shot, hittable, roll;
                if (on->specs->qual <= 0) {
                        makesignal(on, "crew mutinying!", (struct ship *)0);
                        on->specs->qual = 5;
                if (on->specs->qual <= 0) {
                        makesignal(on, "crew mutinying!", (struct ship *)0);
                        on->specs->qual = 5;
-                       Write(W_CAPTURED, on, 0, on-SHIP(0), 0, 0, 0);
+                       Write(W_CAPTURED, on, 0, on->file->index, 0, 0, 0);
                } else 
                        makesignal(on, "crew demoralized", (struct ship *)0);
                Write(W_QUAL, on, 0, on->specs->qual, 0, 0, 0);
                } else 
                        makesignal(on, "crew demoralized", (struct ship *)0);
                Write(W_QUAL, on, 0, on->specs->qual, 0, 0, 0);
@@ -189,53 +189,27 @@ int rig, shot, hittable, roll;
                strike(on, from);
 }
 
                strike(on, from);
 }
 
-cleanfoul(from, to, which)
+Cleansnag(from, to, all, flag)
 register struct ship *from, *to;
 register struct ship *from, *to;
-int which;
+char all, flag;
 {
 {
-       register int n;
-       register struct snag *s = to->file->fouls;
-
-       Write(W_FOUL, from, 0, which, 0, 0, 0);
-       for (n = 0; n < NSHIP && (!s->turnfoul || s->toship != from); n++, s++)
-               ;
-       if (n < NSHIP)
-               Write(W_FOUL, to, 0, n, 0, 0, 0);
-       if (!snagged2(from, to)) {
-               if (!fouled(from) && !grappled(from)) {
-                       unboard(from, from, 1);         /* defense */
-                       unboard(from, from, 0);         /* defense */
-               } else
-                       unboard(from, to, 0);           /* defense */
-               if (!fouled(to) && !grappled(to)) {     /* defense */
-                       unboard(to, to, 1);
-                       unboard(to, to, 0);
-               } else
-                       unboard(to, from, 0);           /* offense */
+       if (flag & 1) {
+               Write(W_UNGRAP, from, 0, to->file->index, all, 0, 0);
+               Write(W_UNGRAP, to, 0, from->file->index, all, 0, 0);
+       }
+       if (flag & 2) {
+               Write(W_UNFOUL, from, 0, to->file->index, all, 0, 0);
+               Write(W_UNFOUL, to, 0, from->file->index, all, 0, 0);
        }
        }
-}
-
-cleangrapple(from, to, which)
-register struct ship *from, *to;
-int which;
-{
-       register int n;
-       register struct snag *s = to->file->grapples;
-
-       Write(W_GRAP, from, 0, which, 0, 0, 0);
-       for (n = 0; n < NSHIP && (!s->turnfoul || s->toship != from); n++, s++)
-               ;
-       if (n < NSHIP)
-               Write(W_GRAP, to, 0, n, 0, 0, 0);
        if (!snagged2(from, to)) {
        if (!snagged2(from, to)) {
-               if (!fouled(from) && !grappled(from)) {
+               if (!snagged(from)) {
                        unboard(from, from, 1);         /* defense */
                        unboard(from, from, 0);         /* defense */
                } else
                        unboard(from, from, 1);         /* defense */
                        unboard(from, from, 0);         /* defense */
                } else
-                       unboard(from, to, 0);           /* defense */
-               if (!fouled(to) && !grappled(to)) {     /* defense */
-                       unboard(to, to, 1);
-                       unboard(to, to, 0);
+                       unboard(from, to, 0);           /* offense */
+               if (!snagged(to)) {
+                       unboard(to, to, 1);             /* defense */
+                       unboard(to, to, 0);             /* defense */
                } else
                        unboard(to, from, 0);           /* offense */
        }
                } else
                        unboard(to, from, 0);           /* offense */
        }
index e89925b..c805e28 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)dr_1.c      2.5 83/12/12";
+static char *sccsid = "@(#)dr_1.c      2.6 83/12/17";
 #endif
 
 #include "driver.h"
 #endif
 
 #include "driver.h"
@@ -34,6 +34,7 @@ char **argv;
                        (void) printf("driver: OUT OF MEMORY\n");
                        exit(0);
                }
                        (void) printf("driver: OUT OF MEMORY\n");
                        exit(0);
                }
+               sp->file->index = sp - SHIP(0);
                sp->file->loadL = L_ROUND;
                sp->file->loadR = L_ROUND;
                sp->file->readyR = R_LOADED|R_INITIAL;
                sp->file->loadL = L_ROUND;
                sp->file->loadR = L_ROUND;
                sp->file->readyR = R_LOADED|R_INITIAL;
@@ -65,23 +66,22 @@ char **argv;
 
 unfoul()
 {
 
 unfoul()
 {
-       register int k;
        register struct ship *sp;
        struct ship *to;
        register int nat;
        register struct ship *sp;
        struct ship *to;
        register int nat;
+       register i;
 
        foreachship(sp) {
                if (sp->file->captain[0])
                        continue;
                nat = capship(sp)->nationality;
 
        foreachship(sp) {
                if (sp->file->captain[0])
                        continue;
                nat = capship(sp)->nationality;
-               for (k = 0; k < NSHIP; k++) {
-                       if (sp->file->fouls[k].turnfoul == 0)
+               foreachship(to) {
+                       if (nat != capship(to)->nationality
+                           && !toughmelee(sp, to, 0, 0))
                                continue;
                                continue;
-                       to = sp->file->fouls[k].toship;
-                       if ((nat == capship(to)->nationality ||
-                            toughmelee(sp, to, 0, 0)) &&
-                           die() <= 2)
-                               cleanfoul(sp, to, k);
+                       for (i = fouled2(sp, to); --i >= 0;)
+                               if (die() <= 2)
+                                       cleanfoul(sp, to, 0);
                }
        }
 }
                }
        }
 }
@@ -94,12 +94,12 @@ boardcomp()
        foreachship(sp) {
                if (*sp->file->captain)
                        continue;
        foreachship(sp) {
                if (*sp->file->captain)
                        continue;
-               if (!fouled(sp) && !grappled(sp))
-                       continue;
                if (sp->file->dir == 0)
                        continue;
                if (sp->file->struck || sp->file->captured != 0)
                        continue;
                if (sp->file->dir == 0)
                        continue;
                if (sp->file->struck || sp->file->captured != 0)
                        continue;
+               if (!snagged(sp))
+                       continue;
                crew[0] = sp->specs->crew1 != 0;
                crew[1] = sp->specs->crew2 != 0;
                crew[2] = sp->specs->crew3 != 0;
                crew[0] = sp->specs->crew1 != 0;
                crew[1] = sp->specs->crew2 != 0;
                crew[2] = sp->specs->crew3 != 0;
@@ -168,7 +168,7 @@ int key;
                fromcap = from;
        if (tocap == 0)
                tocap = to;
                fromcap = from;
        if (tocap == 0)
                tocap = to;
-       if (key) { 
+       if (key) {
                if (!menfrom) {          /* if crew surprised */
                        if (fromcap == from)
                                menfrom = from->specs->crew1
                if (!menfrom) {          /* if crew surprised */
                        if (fromcap == from)
                                menfrom = from->specs->crew1
@@ -228,7 +228,7 @@ int key;
    I guess that what is going on here is that the pointer is multiplied
    or something. */
 
    I guess that what is going on here is that the pointer is multiplied
    or something. */
 
-                       Write(W_CAPTURED, from, 0, to-SHIP(0), 0, 0, 0);
+                       Write(W_CAPTURED, from, 0, to->file->index, 0, 0, 0);
                        topoints = 2 * from->specs->pts + to->file->points;
                        if (from->file->struck)
                                topoints -= from->specs->pts;
                        topoints = 2 * from->specs->pts + to->file->points;
                        if (from->file->struck)
                                topoints -= from->specs->pts;
@@ -465,6 +465,7 @@ next()
        }
 }
 
        }
 }
 
+/*ARGSUSED*/
 /*VARARGS2*/
 Signal(fmt, ship, a, b, c)
 char *fmt;
 /*VARARGS2*/
 Signal(fmt, ship, a, b, c)
 char *fmt;
index c0d7422..c4a7fe0 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)dr_2.c      2.3 83/12/13";
+static char *sccsid = "@(#)dr_2.c      2.4 83/12/17";
 #endif
 
 #include "driver.h"
 #endif
 
 #include "driver.h"
@@ -38,7 +38,6 @@ thinkofgrapples()
 
 checkup()
 {
 
 checkup()
 {
-       register int k;
        register struct ship *sp, *sq;
        register char explode, sink;
 
        register struct ship *sp, *sq;
        register char explode, sink;
 
@@ -52,20 +51,10 @@ checkup()
                if (die() < 5)
                        continue;
                Write(sink == 1 ? W_SINK : W_EXPLODE, sp, 0, 2, 0, 0, 0);
                if (die() < 5)
                        continue;
                Write(sink == 1 ? W_SINK : W_EXPLODE, sp, 0, 2, 0, 0, 0);
-               Write(W_SHIPDIR, sp, 0, 0, 0, 0, 0);
-               if (fouled(sp) || grappled(sp)) {
-                       for (k = 0; k < NSHIP; k++) {
-                               if (sp->file->fouls[k].turnfoul)
-                                       cleanfoul(sp,
-                                               sp->file->fouls[k].toship, k);
-                       }
-                       for (k = 0; k < NSHIP; k++) {
-                               if (sp->file->grapples[k].turnfoul)
-                                       cleangrapple(sp,
-                                               sp->file->grapples[k].toship,
-                                               k);
-                       }
-               }
+               Write(W_DIR, sp, 0, 0, 0, 0, 0);
+               if (snagged(sp))
+                       foreachship(sq)
+                               cleansnag(sp, sq, 1);
                if (sink != 1) {
                        makesignal(sp, "exploding!", (struct ship *)0);
                        foreachship(sq) {
                if (sink != 1) {
                        makesignal(sp, "exploding!", (struct ship *)0);
                        foreachship(sq) {
index e3a8f7a..24fe3b9 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)dr_3.c      2.3 83/12/12";
+static char *sccsid = "@(#)dr_3.c      2.4 83/12/17";
 #endif
 
 #include "driver.h"
 #endif
 
 #include "driver.h"
@@ -8,7 +8,7 @@ moveall()               /* move all comp ships */
 {
        register struct ship *sp, *sq;          /* r11, r10 */
        register int n;                         /* r9 */
 {
        register struct ship *sp, *sq;          /* r11, r10 */
        register int n;                         /* r9 */
-       register int k, l, m;                   /* r8, r7, r6, */
+       register int k, l;                      /* r8, r7 */
        int row[NSHIP], col[NSHIP], dir[NSHIP], drift[NSHIP];
        char moved[NSHIP];
 
        int row[NSHIP], col[NSHIP], dir[NSHIP], drift[NSHIP];
        char moved[NSHIP];
 
@@ -28,12 +28,12 @@ moveall()           /* move all comp ships */
                        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)
-                               *sp->file->last = '\0';
+                               *sp->file->movebuf = '\0';
                        else
                        else
-                               closeon(sp, closest, sp->file->last,
+                               closeon(sp, closest, sp->file->movebuf,
                                        ta, ma, af);
                } else
                                        ta, ma, af);
                } else
-                       *sp->file->last = '\0';
+                       *sp->file->movebuf = '\0';
        }
        /*
         * Then execute the moves for ALL ships (dead ones too),
        }
        /*
         * Then execute the moves for ALL ships (dead ones too),
@@ -44,10 +44,10 @@ moveall()           /* move all comp ships */
        n = 0;
        foreachship(sp) {
                if (snagged(sp))
        n = 0;
        foreachship(sp) {
                if (snagged(sp))
-                       strcpy(sp->file->last, "d");
+                       (void) strcpy(sp->file->movebuf, "d");
                else
                else
-                       if (*sp->file->last != 'd')
-                               strcat(sp->file->last, "d");
+                       if (*sp->file->movebuf != 'd')
+                               (void) strcat(sp->file->movebuf, "d");
                row[n] = sp->file->row;
                col[n] = sp->file->col;
                dir[n] = sp->file->dir;
                row[n] = sp->file->row;
                col[n] = sp->file->col;
                dir[n] = sp->file->dir;
@@ -62,14 +62,14 @@ moveall()           /* move all comp ships */
        for (k = 0; stillmoving(k); k++) {
                /*
                 * Step once.
        for (k = 0; stillmoving(k); k++) {
                /*
                 * Step once.
-                * And propagate the nulls at the end of sp->file->last.
+                * And propagate the nulls at the end of sp->file->movebuf.
                 */
                n = 0;
                foreachship(sp) {
                 */
                n = 0;
                foreachship(sp) {
-                       if (!sp->file->last[k])
-                               sp->file->last[k+1] = '\0';
+                       if (!sp->file->movebuf[k])
+                               sp->file->movebuf[k+1] = '\0';
                        else if (sp->file->dir)
                        else if (sp->file->dir)
-                               step(sp->file->last[k], sp, &moved[n]);
+                               step(sp->file->movebuf[k], sp, &moved[n]);
                        n++;
                }
                /*
                        n++;
                }
                /*
@@ -98,22 +98,14 @@ moveall()           /* move all comp ships */
                                                makesignal(sp,
                                                        "fouled with %s (%c%c)",
                                                        sq);
                                                makesignal(sp,
                                                        "fouled with %s (%c%c)",
                                                        sq);
-                                               for (m = 0; m < NSHIP && sp->file->fouls[m].turnfoul; m++)
-                                                       ;
-                                               if (m < NSHIP)
-                                                       Write(W_FOUL, sp, 0,
-                                                               m, turn, l, 0);
-                                               for (m = 0; m < NSHIP && sq->file->fouls[m].turnfoul; m++)
-                                                       ;
-                                               if (m < NSHIP)
-                                                       Write(W_FOUL, sq, 0,
-                                                               m, turn, n, 0);
+                                               Write(W_FOUL, sp, 0, l, 0, 0, 0);
+                                               Write(W_FOUL, sq, 0, n, 0, 0, 0);
                                        }
                                        snap++;
                                }
                                if (snap) {
                                        }
                                        snap++;
                                }
                                if (snap) {
-                                       sp->file->last[k + 1] = 0;
-                                       sq->file->last[k + 1] = 0;
+                                       sp->file->movebuf[k + 1] = 0;
+                                       sq->file->movebuf[k + 1] = 0;
                                        sq->file->row = sp->file->row - 1;
                                        if (sp->file->dir == 1
                                            || sp->file->dir == 5)
                                        sq->file->row = sp->file->row - 1;
                                        if (sp->file->dir == 1
                                            || sp->file->dir == 5)
@@ -136,13 +128,13 @@ moveall()         /* move all comp ships */
        n = 0;
        foreachship(sp) {
                if (sp->file->dir != 0) {
        n = 0;
        foreachship(sp) {
                if (sp->file->dir != 0) {
-                       *sp->file->last = 0;
+                       *sp->file->movebuf = 0;
                        if (row[n] != sp->file->row)
                        if (row[n] != sp->file->row)
-                               Write(W_SHIPROW, sp, 0, sp->file->row, 0, 0, 0);
+                               Write(W_ROW, sp, 0, sp->file->row, 0, 0, 0);
                        if (col[n] != sp->file->col)
                        if (col[n] != sp->file->col)
-                               Write(W_SHIPCOL, sp, 0, sp->file->col, 0, 0, 0);
+                               Write(W_COL, sp, 0, sp->file->col, 0, 0, 0);
                        if (dir[n] != sp->file->dir)
                        if (dir[n] != sp->file->dir)
-                               Write(W_SHIPDIR, sp, 0, sp->file->dir, 0, 0, 0);
+                               Write(W_DIR, sp, 0, sp->file->dir, 0, 0, 0);
                        if (drift[n] != sp->file->drift)
                                Write(W_DRIFT, sp, 0, sp->file->drift, 0, 0, 0);
                }
                        if (drift[n] != sp->file->drift)
                                Write(W_DRIFT, sp, 0, sp->file->drift, 0, 0, 0);
                }
@@ -156,7 +148,7 @@ register int k;
        register struct ship *sp;
 
        foreachship(sp)
        register struct ship *sp;
 
        foreachship(sp)
-               if (sp->file->last[k])
+               if (sp->file->movebuf[k])
                        return 1;
        return 0;
 }
                        return 1;
        return 0;
 }
@@ -242,7 +234,7 @@ char isdefense;
                ;
        if (n < 3 && sections) {
                Write(isdefense ? W_DBP : W_OBP, from, 0,
                ;
        if (n < 3 && sections) {
                Write(isdefense ? W_DBP : W_OBP, from, 0,
-                       turn, to-SHIP(0), sections, 0);
+                       turn, to->file->index, sections, 0);
                if (isdefense)
                        makesignal(from, "repelling boarders",
                                (struct ship *)0);
                if (isdefense)
                        makesignal(from, "repelling boarders",
                                (struct ship *)0);
index 04c620d..b0c4ac2 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)dr_4.c      2.1 83/10/31";
+static char *sccsid = "@(#)dr_4.c      2.2 83/12/17";
 #endif
 #include "externs.h"
 
 #endif
 #include "externs.h"
 
@@ -7,15 +7,14 @@ ungrap(from, to)
 register struct ship *from, *to;
 {
        register k;
 register struct ship *from, *to;
 {
        register k;
-       register struct snag *sp = from->file->grapples;
+       char friend;
 
 
-       if (grappled2(from, to)) {
-               for (k = 0; k < NSHIP; k++, sp++) {
-                       if (sp->turnfoul == 0 || to != sp->toship)
-                               continue;
-                       if (from->nationality == to->nationality && die() >= 3)
-                               continue;
-                       cleangrapple(from, to, k);
+       if ((k = grappled2(from, to)) == 0)
+               return;
+       friend = capship(from)->nationality == capship(to)->nationality;
+       while (--k >= 0) {
+               if (friend || die() < 3) {
+                       cleangrapple(from, to, 0);
                        makesignal(from, "ungrappling %s (%c%c)", to);
                }
        }
                        makesignal(from, "ungrappling %s (%c%c)", to);
                }
        }
@@ -24,17 +23,9 @@ register struct ship *from, *to;
 grap(from, to)
 register struct ship *from, *to;
 {
 grap(from, to)
 register struct ship *from, *to;
 {
-       register l;
-
-       if (from->nationality != capship(to)->nationality && die() >= 3)
+       if (capship(from)->nationality != capship(to)->nationality && die() > 2)
                return;
                return;
-       for (l = 0; l < NSHIP && from->file->grapples[l].turnfoul; l++)
-               ;
-       if (l < NSHIP)
-               Write(W_GRAP, from, 0, l, turn, to-SHIP(0), 0);
-       for (l = 0; l < NSHIP && to->file->grapples[l].turnfoul; l++)
-               ;
-       if (l < NSHIP)
-               Write(W_GRAP, to, 0, l, turn, from-SHIP(0), 0);
+       Write(W_GRAP, from, 0, to->file->index, 0, 0, 0);
+       Write(W_GRAP, to, 0, from->file->index, 0, 0, 0);
        makesignal(from, "grappled with %s (%c%c)", to);
 }
        makesignal(from, "grappled with %s (%c%c)", to);
 }
index 9c0a0dc..5f80581 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * @(#)extern.h        2.2 83/11/03
+ * @(#)extern.h        2.3 83/12/17
  */
 #include <stdio.h>
 #include <signal.h>
  */
 #include <stdio.h>
 #include <signal.h>
 #define abs(a)         ((a) > 0 ? (a) : -(a))
 #define min(a,b)       ((a) < (b) ? (a) : (b))
 
 #define abs(a)         ((a) > 0 ? (a) : -(a))
 #define min(a,b)       ((a) < (b) ? (a) : (b))
 
-#define grappled(a)    Snagged(a, 1)
-#define fouled(a)      Snagged(a, 0)
-#define snagged(a)     (Snagged(a, 0) || Snagged(a, 1))
-#define grappled2(a,b) Snagged2(a, b, 1, 0)
-#define fouled2(a,b)   Snagged2(a, b, 0, 0)
-#define snagged2(a,b)  (Snagged2(a, b, 0, 0) || Snagged2(a, b, 1, 0))
-#define Xgrappled2(a,b)        Snagged2(a, b, 1, 1)
-#define Xfouled2(a,b)  Snagged2(a, b, 0, 1)
-#define Xsnagged2(a,b) (Snagged2(a, b, 0, 1) || Snagged2(a, b, 1, 1))
+#define grappled(a)    ((a)->file->ngrap)
+#define fouled(a)      ((a)->file->nfoul)
+#define snagged(a)     (grappled(a) + fouled(a))
+
+#define grappled2(a, b)        ((a)->file->grap[(b)->file->index].sn_count)
+#define fouled2(a, b)  ((a)->file->foul[(b)->file->index].sn_count)
+#define snagged2(a, b) (grappled2(a, b) + fouled2(a, b))
+
+#define Xgrappled2(a, b) ((a)->file->grap[(b)->file->index].sn_turn < turn-1 ? grappled2(a, b) : 0)
+#define Xfouled2(a, b) ((a)->file->foul[(b)->file->index].sn_turn < turn-1 ? fouled2(a, b) : 0)
+#define Xsnagged2(a, b)        (Xgrappled2(a, b) + Xfouled2(a, b))
+
+#define cleangrapple(a, b, c)  Cleansnag(a, b, c, 1)
+#define cleanfoul(a, b, c)     Cleansnag(a, b, c, 2)
+#define cleansnag(a, b, c)     Cleansnag(a, b, c, 3)
 
 #define sterncolour(sp)        ((sp)->file->stern+'0'-((sp)->file->captured?10:0))
 #define sternrow(sp)   ((sp)->file->row + dr[(sp)->file->dir])
 
 #define sterncolour(sp)        ((sp)->file->stern+'0'-((sp)->file->captured?10:0))
 #define sternrow(sp)   ((sp)->file->row + dr[(sp)->file->dir])
 #define W_GUNL         10
 #define W_GUNR         11
 #define W_HULL         12
 #define W_GUNL         10
 #define W_GUNR         11
 #define W_HULL         12
-#define W_LAST         13
+#define W_MOVE         13
 #define W_OBP          14
 #define W_PCREW                15
 #define W_OBP          14
 #define W_PCREW                15
-/* 16 */
+#define W_UNFOUL       16
 #define W_POINTS       17
 #define W_QUAL         18
 #define W_POINTS       17
 #define W_QUAL         18
-/* 19 */
+#define W_UNGRAP       19
 #define W_RIGG         20
 #define W_RIGG         20
-#define W_SHIPCOL      21
-#define W_SHIPDIR      22
-#define W_SHIPROW      23
+#define W_COL          21
+#define W_DIR          22
+#define W_ROW          23
 #define W_SIGNAL       24
 #define W_SINK         25
 #define W_STRUCK       26
 #define W_SIGNAL       24
 #define W_SINK         25
 #define W_STRUCK       26
@@ -103,8 +109,8 @@ struct BP {
 };
 
 struct snag {
 };
 
 struct snag {
-       short turnfoul;
-       struct ship *toship;
+       short sn_count;
+       short sn_turn;
 };
 
 #define NSCENE nscene
 };
 
 #define NSCENE nscene
@@ -122,6 +128,7 @@ struct snag {
 #define N_O    7
 
 struct File {
 #define N_O    7
 
 struct File {
+       int index;
        char captain[20];               /* 0 */
        short points;                   /* 20 */
        char loadL;                     /* 22 */
        char captain[20];               /* 0 */
        short points;                   /* 20 */
        char loadL;                     /* 22 */
@@ -133,10 +140,12 @@ struct File {
        char struck;                    /* 66 */
        struct ship *captured;          /* 68 */
        short pcrew;                    /* 70 */
        char struck;                    /* 66 */
        struct ship *captured;          /* 68 */
        short pcrew;                    /* 70 */
-       char last[10];                  /* 72 */
+       char movebuf[10];               /* 72 */
        char drift;                     /* 82 */
        char drift;                     /* 82 */
-       struct snag fouls[NSHIP];       /* 84 */
-       struct snag grapples[NSHIP];    /* 124 */
+       short nfoul;
+       short ngrap;
+       struct snag foul[NSHIP];        /* 84 */
+       struct snag grap[NSHIP];        /* 124 */
        char RH;                        /* 224 */
        char RG;                        /* 226 */
        char RR;                        /* 228 */
        char RH;                        /* 224 */
        char RG;                        /* 226 */
        char RR;                        /* 228 */
index 118af99..eede19e 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)parties.c   2.1 83/10/31";
+static char *sccsid = "@(#)parties.c   2.2 83/12/17";
 #endif
 
 #include "externs.h"
 #endif
 
 #include "externs.h"
@@ -30,39 +30,6 @@ char isdefense;
        return 0;
 }
 
        return 0;
 }
 
-Snagged(ship, isgrap)
-struct ship *ship;
-char isgrap;
-{
-       register int Snags = 0;
-       register struct snag *sp, *sq;
-
-       sp = isgrap ? ship->file->grapples : ship->file->fouls;
-       sq = sp + NSHIP;
-       for (; sp < sq; sp++)
-               if (sp->turnfoul)
-                       Snags++;
-       return Snags;
-}
-
-Snagged2(ship, to, isgrap, isX)
-struct ship *ship, *to;
-char isgrap, isX;
-{
-       register Snags = 0;
-       register struct snag *sp, *sq;
-
-       sp = isgrap ? ship->file->grapples : ship->file->fouls;
-       sq = sp + NSHIP;
-       for (; sp < sq; sp++) {
-               if (sp->turnfoul && sp->toship == to
-                   && (!isX || sp->turnfoul < turn - 1
-                               && ship->file->loadwith==L_GRAPE))
-                       Snags++;
-       }
-       return Snags;
-}
-
 unboard(ship, to, isdefense)
 register struct ship *ship, *to;
 register char isdefense;
 unboard(ship, to, isdefense)
 register struct ship *ship, *to;
 register char isdefense;
index c68279e..4f486e9 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)pl_1.c      2.4 83/12/09";
+static char *sccsid = "@(#)pl_1.c      2.5 83/12/17";
 #endif
 
 #include "player.h"
 #endif
 
 #include "player.h"
@@ -90,6 +90,7 @@ reprint:
                        (void) puts("OUT OF MEMORY");
                        exit(0);
                }
                        (void) puts("OUT OF MEMORY");
                        exit(0);
                }
+               sp->file->index = sp - SHIP(0);
                sp->file->stern = nat[sp->nationality]++;
                sp->file->dir = sp->shipdir;
                sp->file->row = sp->shiprow;
                sp->file->stern = nat[sp->nationality]++;
                sp->file->dir = sp->shipdir;
                sp->file->row = sp->shiprow;
@@ -132,7 +133,7 @@ reprint:
                        printf("%s\n\n", cc->name);
                        foreachship(sp)
                                printf("  %2d:  %-10s %-15s  (%-2d pts)   %s\n",
                        printf("%s\n\n", cc->name);
                        foreachship(sp)
                                printf("  %2d:  %-10s %-15s  (%-2d pts)   %s\n",
-                                       sp - SHIP(0),
+                                       sp->file->index,
                                        countryname[sp->nationality],
                                        sp->shipname,
                                        sp->specs->pts,
                                        countryname[sp->nationality],
                                        sp->shipname,
                                        sp->specs->pts,
@@ -254,7 +255,6 @@ int conditions;
        FILE *fp;
        int persons;
        float net;
        FILE *fp;
        int persons;
        float net;
-       char message[60];
        register int n;
        struct logs log[10], temp;
 
        register int n;
        struct logs log[10], temp;
 
index 5f9bfe7..67114a4 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)pl_3.c      2.2 83/12/09";
+static char *sccsid = "@(#)pl_3.c      2.3 83/12/17";
 #endif
 
 #include "player.h"
 #endif
 
 #include "player.h"
@@ -178,48 +178,31 @@ acceptcombat()
 grapungrap()
 {
        register struct ship *sp;
 grapungrap()
 {
        register struct ship *sp;
-       register int n, k;
-       register struct snag *p;
-       int r;
+       register int i;
 
 
-       n = -1;
        foreachship(sp) {
        foreachship(sp) {
-               n++;
-               if (sp == ms)
+               if (sp == ms || sp->file->dir == 0)
                        continue;
                        continue;
-               r = range(ms, sp);
-               if ((r < 0 || r > 1) && !grappled2(ms, sp))
+               if (range(ms, sp) > 1 && !grappled2(ms, sp))
                        continue;
                switch (sgetch("Attempt to grapple or ungrapple %s (%c%c): ",
                        sp, 1)) {
                case 'g':
                        if (die() < 3
                            || ms->nationality == capship(sp)->nationality) {
                        continue;
                switch (sgetch("Attempt to grapple or ungrapple %s (%c%c): ",
                        sp, 1)) {
                case 'g':
                        if (die() < 3
                            || ms->nationality == capship(sp)->nationality) {
-                               for (k = 0, p = mf->grapples;
-                                    k < NSHIP && p->turnfoul; k++, p++)
-                                       ;               /* XXX */
-                               if (k < NSHIP)
-                                       Write(W_GRAP, ms, 0, k, turn, n, 0);
-                               for (k = 0, p = sp->file->grapples;
-                                    k < NSHIP && p->turnfoul; k++, p++)
-                                       ;               /* XXX */
-                               if (k < NSHIP)
-                                       Write(W_GRAP, sp, 0,
-                                               k, turn, player, 0);
+                               Write(W_GRAP, ms, 0, sp->file->index, 0, 0, 0);
+                               Write(W_GRAP, sp, 0, player, 0, 0, 0);
                                Signal("Attempt succeeds!", (struct ship *)0);
                                makesignal(ms, "grappled with %s (%c%c)", sp);
                        } else
                                Signal("Attempt fails.", (struct ship *)0);
                        break;
                case 'u':
                                Signal("Attempt succeeds!", (struct ship *)0);
                                makesignal(ms, "grappled with %s (%c%c)", sp);
                        } else
                                Signal("Attempt fails.", (struct ship *)0);
                        break;
                case 'u':
-                       for (k = 0; k < NSHIP; k++) {
-                               if (!mf->grapples[k].turnfoul)
-                                       continue;
-                               if (sp != mf->grapples[k].toship)
-                                       continue;
-                               if (die() < 3 || ms->nationality
-                                   == capship(sp)->nationality) {
-                                       cleangrapple(ms, sp, k);
+                       for (i = grappled2(ms, sp); --i >= 0;) {
+                               if (ms->nationality
+                                       == capship(sp)->nationality
+                                   || die() < 3) {
+                                       cleangrapple(ms, sp, 0);
                                        Signal("Attempt succeeds!",
                                                (struct ship *)0);
                                        makesignal(ms,
                                        Signal("Attempt succeeds!",
                                                (struct ship *)0);
                                        makesignal(ms,
@@ -229,24 +212,24 @@ grapungrap()
                                        Signal("Attempt fails.",
                                                (struct ship *)0);
                        }
                                        Signal("Attempt fails.",
                                                (struct ship *)0);
                        }
+                       break;
                }
        }
 }
 
 unfoulplayer()
 {
                }
        }
 }
 
 unfoulplayer()
 {
-       register struct snag *s = mf->fouls;
        register struct ship *to;
        register struct ship *to;
-       int n;
+       register i;
 
 
-       for (n = 0; n < NSHIP; n++, s++) {
-               if (s->turnfoul == 0)
+       foreachship(to) {
+               if (fouled2(ms, to) == 0)
+                       continue;
+               if (sgetch("Attempt to unfoul with the %s (%c%c)? ", to, 1) != 'y')
                        continue;
                        continue;
-               to = s->toship;
-               if (sgetch("Attempt to unfoul with the %s (%c%c)? ", to, 1)
-                   == 'y') {
-                       if (die() < 3) {
-                               cleanfoul(ms, to, n);
+               for (i = fouled2(ms, to); --i >= 0;) {
+                       if (die() <= 2) {
+                               cleanfoul(ms, to, 0);
                                Signal("Attempt succeeds!", (struct ship *)0);
                                makesignal(ms, "Unfouling %s (%c%c)", to);
                        } else
                                Signal("Attempt succeeds!", (struct ship *)0);
                                makesignal(ms, "Unfouling %s (%c%c)", to);
                        } else
index 5864064..b3e702b 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * sccsid = "@(#)player.h      2.4 %G%";
+ * sccsid = "@(#)player.h      2.5 %G%";
  */
 #include <curses.h>
 #include "externs.h"
  */
 #include <curses.h>
 #include "externs.h"
@@ -68,7 +68,7 @@ char done_curses;
 char loaded, fired, changed, repaired;
 char dont_adjust;
 int viewrow, viewcol;
 char loaded, fired, changed, repaired;
 char dont_adjust;
 int viewrow, viewcol;
-char movebuf[10];
+char movebuf[sizeof SHIP(0)->file->movebuf];
 char version[];
 int player;
 struct ship *ms;               /* memorial structure, &cc->ship[player] */
 char version[];
 int player;
 struct ship *ms;               /* memorial structure, &cc->ship[player] */
index 3cde4d1..f2573dc 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)sync.c      2.2 83/11/01";
+static char *sccsid = "@(#)sync.c      2.3 83/12/17";
 #endif
 
 #include "externs.h"
 #endif
 
 #include "externs.h"
@@ -39,11 +39,11 @@ sync_exists(game)
        time_t t;
 
        (void) sprintf(buf, SF, game);
        time_t t;
 
        (void) sprintf(buf, SF, game);
-       time(&t);
+       (void) time(&t);
        if (stat(buf, &s) < 0)
                return 0;
        if (s.st_mtime < t - 60*60*2) {         /* 2 hours */
        if (stat(buf, &s) < 0)
                return 0;
        if (s.st_mtime < t - 60*60*2) {         /* 2 hours */
-               unlink(buf);
+               (void) unlink(buf);
                return 0;
        } else
                return 1;
                return 0;
        } else
                return 1;
@@ -87,10 +87,10 @@ int a, b, c, d;
 {
        if (isstr)
                (void) sprintf(sync_bufp, "%d %d %d %s\n",
 {
        if (isstr)
                (void) sprintf(sync_bufp, "%d %d %d %s\n",
-                       type, ship-SHIP(0), isstr, a);
+                       type, ship->file->index, isstr, a);
        else
                (void) sprintf(sync_bufp, "%d %d %d %d %d %d %d\n",
        else
                (void) sprintf(sync_bufp, "%d %d %d %d %d %d %d\n",
-                       type, ship-SHIP(0), isstr, a, b, c, d);
+                       type, ship->file->index, isstr, a, b, c, d);
        while (*sync_bufp++)
                ;
        sync_bufp--;
        while (*sync_bufp++)
                ;
        sync_bufp--;
@@ -167,21 +167,50 @@ int a, b, c, d;
                break;
                }
        case W_FOUL: {
                break;
                }
        case W_FOUL: {
-               register struct snag *p = &ship->file->fouls[a];
-               p->turnfoul = b;
-               p->toship = SHIP(c);
+               register struct snag *p = &ship->file->foul[a];
+               if (SHIP(a)->file->dir == 0)
+                       break;
+               if (p->sn_count++ == 0)
+                       p->sn_turn = turn;
+               ship->file->nfoul++;
                break;
                }
        case W_GRAP: {
                break;
                }
        case W_GRAP: {
-               register struct snag *p = &ship->file->grapples[a];
-               p->turnfoul = b;
-               p->toship = SHIP(c);
+               register struct snag *p = &ship->file->grap[a];
+               if (SHIP(a)->file->dir == 0)
+                       break;
+               if (p->sn_count++ == 0)
+                       p->sn_turn = turn;
+               ship->file->ngrap++;
+               break;
+               }
+       case W_UNFOUL: {
+               register struct snag *p = &ship->file->foul[a];
+               if (p->sn_count > 0)
+                       if (b) {
+                               ship->file->nfoul -= p->sn_count;
+                               p->sn_count = 0;
+                       } else {
+                               ship->file->nfoul--;
+                               p->sn_count--;
+                       }
+               break;
+               }
+       case W_UNGRAP: {
+               register struct snag *p = &ship->file->grap[a];
+               if (p->sn_count > 0)
+                       if (b) {
+                               ship->file->ngrap -= p->sn_count;
+                               p->sn_count = 0;
+                       } else {
+                               ship->file->ngrap--;
+                               p->sn_count--;
+                       }
                break;
                }
        case W_SIGNAL:
                break;
                }
        case W_SIGNAL:
-               if (isplayer) {
+               if (isplayer)
                        Signal("\7%s (%c%c): %s", ship, a);
                        Signal("\7%s (%c%c): %s", ship, a);
-               }
                break;
        case W_CREW: {
                register struct shipspecs *s = ship->specs;
                break;
        case W_CREW: {
                register struct shipspecs *s = ship->specs;
@@ -229,10 +258,10 @@ int a, b, c, d;
        case W_HULL:
                ship->specs->hull = a;
                break;
        case W_HULL:
                ship->specs->hull = a;
                break;
-       case W_LAST:
-               (void) strncpy(ship->file->last, (char *)a,
-                       sizeof ship->file->last - 1);
-               ship->file->last[sizeof ship->file->last - 1] = 0;
+       case W_MOVE:
+               (void) strncpy(ship->file->movebuf, (char *)a,
+                       sizeof ship->file->movebuf - 1);
+               ship->file->movebuf[sizeof ship->file->movebuf - 1] = 0;
                break;
        case W_PCREW:
                ship->file->pcrew = a;
                break;
        case W_PCREW:
                ship->file->pcrew = a;
@@ -263,13 +292,13 @@ int a, b, c, d;
        case W_RIG4:
                ship->specs->rig4 = a;
                break;
        case W_RIG4:
                ship->specs->rig4 = a;
                break;
-       case W_SHIPCOL:
+       case W_COL:
                ship->file->col = a;
                break;
                ship->file->col = a;
                break;
-       case W_SHIPDIR:
+       case W_DIR:
                ship->file->dir = a;
                break;
                ship->file->dir = a;
                break;
-       case W_SHIPROW:
+       case W_ROW:
                ship->file->row = a;
                break;
        case W_SINK:
                ship->file->row = a;
                break;
        case W_SINK: