Repair algorithm fixed.
[unix-history] / usr / src / games / sail / pl_3.c
index 240f873..67114a4 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)pl_3.c      1.3 83/10/14";
+static char *sccsid = "@(#)pl_3.c      2.3 83/12/17";
 #endif
 
 #include "player.h"
 #endif
 
 #include "player.h"
@@ -60,8 +60,8 @@ acceptcombat()
                Signal("%s (%c%c) within range of %s broadside.",
                        closest, r ? "right" : "left");
                if (load > L_CHAIN && target < 6) {
                Signal("%s (%c%c) within range of %s broadside.",
                        closest, r ? "right" : "left");
                if (load > L_CHAIN && target < 6) {
-                       Signal("Aim for hull or rigging? ", (struct ship *)0);
-                       switch (sgetch(1)) {
+                       switch (sgetch("Aim for hull or rigging? ",
+                               (struct ship *)0, 1)) {
                        case 'r':
                                shootat = RIGGING;
                                break;
                        case 'r':
                                shootat = RIGGING;
                                break;
@@ -74,8 +74,7 @@ acceptcombat()
                                        (struct ship *)0);
                        }
                } else {
                                        (struct ship *)0);
                        }
                } else {
-                       Signal("Fire? ", (struct ship *)0);
-                       if (sgetch(1) == 'n') {
+                       if (sgetch("Fire? ", (struct ship *)0, 1) == 'n') {
                                shootat = -1;
                                Signal("Belay that! Hold your fire.",
                                        (struct ship *)0);
                                shootat = -1;
                                Signal("Belay that! Hold your fire.",
                                        (struct ship *)0);
@@ -155,13 +154,10 @@ acceptcombat()
                        }
                        table(shootat, load, hit, closest, ms, roll);
                }
                        }
                        table(shootat, load, hit, closest, ms, roll);
                }
-               Scroll2();
-               (void) wprintw(scroll_w, "Damage inflicted on the %s:",
-                       closest->shipname);
-               Scroll();
-               (void) wprintw(scroll_w,
-                       "\t%d HULL, %d GUNS, %d CREW, %d RIGGING",
-                       hhits, ghits, chits, rhits);
+               Signal("Damage inflicted on the %s:",
+                       (struct ship *)0, closest->shipname);
+               Signal("\t%d HULL, %d GUNS, %d CREW, %d RIGGING",
+                       (struct ship *)0, hhits, ghits, chits, rhits);
                if (!r) {
                        mf->loadL = L_EMPTY;
                        mf->readyL = R_EMPTY;
                if (!r) {
                        mf->loadL = L_EMPTY;
                        mf->readyL = R_EMPTY;
@@ -174,53 +170,39 @@ acceptcombat()
                Signal("Unable to fire %s broadside",
                        (struct ship *)0, r ? "right" : "left");
        }
                Signal("Unable to fire %s broadside",
                        (struct ship *)0, r ? "right" : "left");
        }
+       blockalarm();
+       draw_stat();
+       unblockalarm();
 }
 
 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;
                        continue;
-               Signal("Attempt to grapple or ungrapple %s (%c%c): ", sp);
-               switch (sgetch(1)) {
+               switch (sgetch("Attempt to grapple or ungrapple %s (%c%c): ",
+                       sp, 1)) {
                case 'g':
                        if (die() < 3
                            || ms->nationality == capship(sp)->nationality) {
                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,
@@ -230,85 +212,28 @@ 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;
                        continue;
-               to = s->toship;
-               Signal("Attempt to unfoul with the %s (%c%c)? ", to);
-               if (sgetch(1) == 'y') {
-                       if (die() < 3) {
-                               cleanfoul(ms, to, n);
-                               Signal("Attempt succeeds!",
-                                       (struct ship *)0);
+               if (sgetch("Attempt to unfoul with the %s (%c%c)? ", to, 1) != 'y')
+                       continue;
+               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 fails.", (struct ship *)0);
                }
        }
 }
                                makesignal(ms, "Unfouling %s (%c%c)", to);
                        } else
                                Signal("Attempt fails.", (struct ship *)0);
                }
        }
 }
-
-lookout()
-{
-       register struct ship *sp;
-       char buf[3];
-       register char c;
-
-       Signal("What ship? ", (struct ship *)0);
-       sgetstr(buf, sizeof buf);
-       foreachship(sp) {
-               c = *countryname[sp->nationality];
-               if ((c == *buf || tolower(c) == *buf || colours(sp) == *buf)
-                   && (sp->file->stern == buf[1] || sterncolour(sp) == buf[1]))
-               {
-                       eyeball(sp);
-                       return;
-               }
-       }
-       Signal("No such ship.", (struct ship *)0);
-}
-
-char *
-saywhat(sp, flag)
-register struct ship *sp;
-char flag;
-{
-       if (sp->file->captain[0])
-               return sp->file->captain;
-       else if (sp->file->struck)
-               return "(struck)";
-       else if (sp->file->captured != 0)
-               return "(captured)";
-       else if (flag)
-               return "(available)";
-       else
-               return "(computer)";
-}
-
-eyeball(ship)
-register struct ship *ship;
-{
-       int i;
-
-       if (ship == 0)
-               Signal("No more ships left.", (struct ship *)0);
-       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;
-               if (i <= 0)
-                       i += 8;
-               Signal("%s (%c%c) %s %s %s.",
-                       ship, countryname[ship->nationality],
-                       classname[ship->specs->class], directionname[i]);
-       }
-}