BSD 4_3_Net_2 release
[unix-history] / usr / src / games / sail / pl_7.c
index 765b5dc..136db8b 100644 (file)
@@ -1,6 +1,39 @@
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)pl_7.c      1.1 83/10/28";
-#endif
+static char sccsid[] = "@(#)pl_7.c     5.7 (Berkeley) 2/28/91";
+#endif /* not lint */
 
 #include "player.h"
 
 
 #include "player.h"
 
@@ -15,7 +48,7 @@ static int sc_line;
 
 initscreen()
 {
 
 initscreen()
 {
-       (void) initscr();
+       /* initscr() already done in SCREENTEST() */
        view_w = newwin(VIEW_Y, VIEW_X, VIEW_T, VIEW_L);
        slot_w = newwin(SLOT_Y, SLOT_X, SLOT_T, SLOT_L);
        scroll_w = newwin(SCROLL_Y, SCROLL_X, SCROLL_T, SCROLL_L);
        view_w = newwin(VIEW_Y, VIEW_X, VIEW_T, VIEW_L);
        slot_w = newwin(SLOT_Y, SLOT_X, SLOT_T, SLOT_L);
        scroll_w = newwin(SCROLL_Y, SCROLL_X, SCROLL_T, SCROLL_L);
@@ -26,21 +59,28 @@ initscreen()
        (void) leaveok(slot_w, 1);
        (void) leaveok(stat_w, 1);
        (void) leaveok(turn_w, 1);
        (void) leaveok(slot_w, 1);
        (void) leaveok(stat_w, 1);
        (void) leaveok(turn_w, 1);
+#ifdef SIGTSTP
+       {
+               void susp();
+               (void) signal(SIGTSTP, susp);
+       }
+#endif
        noecho();
        crmode();
 }
 
 cleanupscreen()
 {
        noecho();
        crmode();
 }
 
 cleanupscreen()
 {
+       /* alarm already turned off */
        if (done_curses) {
        if (done_curses) {
+               (void) wmove(scroll_w, SCROLL_Y - 1, 0);
+               (void) wclrtoeol(scroll_w);
                draw_screen();
                draw_screen();
-               (void) move(LINES - 1, 0);
-               (void) clrtoeol();
-               (void) refresh();
                endwin();
        }
 }
 
                endwin();
        }
 }
 
+void
 newturn()
 {
        repaired = loaded = fired = changed = 0;
 newturn()
 {
        repaired = loaded = fired = changed = 0;
@@ -57,12 +97,17 @@ newturn()
                        mf->readyR = R_LOADING;
                else
                        mf->readyR = R_LOADED;
                        mf->readyR = R_LOADING;
                else
                        mf->readyR = R_LOADED;
+       if (!hasdriver)
+               Write(W_DDEAD, SHIP(0), 0, 0, 0, 0, 0);
 
        if (sc_hasprompt) {
                (void) wmove(scroll_w, sc_line, 0);
                (void) wclrtoeol(scroll_w);
        }
 
        if (sc_hasprompt) {
                (void) wmove(scroll_w, sc_line, 0);
                (void) wclrtoeol(scroll_w);
        }
-       Sync();
+       if (Sync() < 0)
+               leave(LEAVE_SYNC);
+       if (!hasdriver)
+               leave(LEAVE_DRIVER);
        if (sc_hasprompt)
                (void) wprintw(scroll_w, "%s%s", sc_prompt, sc_buf);
 
        if (sc_hasprompt)
                (void) wprintw(scroll_w, "%s%s", sc_prompt, sc_buf);
 
@@ -119,9 +164,11 @@ struct ship *ship;
 {
        static char buf[60];
 
 {
        static char buf[60];
 
-       if (ship != 0)
-               p = sprintf(buf, p, ship->shipname, colours(ship),
+       if (ship != 0) {
+               (void)sprintf(buf, p, ship->shipname, colours(ship),
                        sterncolour(ship));
                        sterncolour(ship));
+               p = buf;
+       }
        sc_prompt = p;
        sc_buf = "";
        sc_hasprompt = 1;
        sc_prompt = p;
        sc_buf = "";
        sc_hasprompt = 1;
@@ -144,7 +191,9 @@ char flag;
        register c;
 
        prompt(p, ship);
        register c;
 
        prompt(p, ship);
+       blockalarm();
        (void) wrefresh(scroll_w);
        (void) wrefresh(scroll_w);
+       unblockalarm();
        while ((c = wgetch(scroll_w)) == EOF)
                ;
        if (flag && c >= ' ' && c < 0x7f)
        while ((c = wgetch(scroll_w)) == EOF)
                ;
        if (flag && c >= ' ' && c < 0x7f)
@@ -165,7 +214,9 @@ register n;
        sc_buf = buf;
        for (;;) {
                *p = 0;
        sc_buf = buf;
        for (;;) {
                *p = 0;
+               blockalarm();
                (void) wrefresh(scroll_w);
                (void) wrefresh(scroll_w);
+               unblockalarm();
                while ((c = wgetch(scroll_w)) == EOF)
                        ;
                switch (c) {
                while ((c = wgetch(scroll_w)) == EOF)
                        ;
                switch (c) {
@@ -184,7 +235,7 @@ register n;
                                *p++ = c;
                                (void) waddch(scroll_w, c);
                        } else
                                *p++ = c;
                                (void) waddch(scroll_w, c);
                        } else
-                               (void) putchar(CTRL(g));
+                               (void) putchar(CTRL('g'));
                }
        }
 }
                }
        }
 }
@@ -224,7 +275,7 @@ draw_view()
 draw_turn()
 {
        (void) wmove(turn_w, 0, 0);
 draw_turn()
 {
        (void) wmove(turn_w, 0, 0);
-       (void) wprintw(turn_w, "Turn %d", turn);
+       (void) wprintw(turn_w, "%cTurn %d", dont_adjust?'*':'-', turn);
        (void) wrefresh(turn_w);
 }
 
        (void) wrefresh(turn_w);
 }
 
@@ -259,7 +310,7 @@ draw_stat()
        (void) wprintw(stat_w, "Crew %2d %2d %2d\n",
                mc->crew1, mc->crew2, mc->crew3);
        (void) wprintw(stat_w, "Guns %2d %2d\n", mc->gunL, mc->gunR);
        (void) wprintw(stat_w, "Crew %2d %2d %2d\n",
                mc->crew1, mc->crew2, mc->crew3);
        (void) wprintw(stat_w, "Guns %2d %2d\n", mc->gunL, mc->gunR);
-       (void) wprintw(stat_w, "Carr %2d %2d\n", mc->carR, mc->carL);
+       (void) wprintw(stat_w, "Carr %2d %2d\n", mc->carL, mc->carR);
        (void) wprintw(stat_w, "Rigg %d %d %d ", mc->rig1, mc->rig2, mc->rig3);
        if (mc->rig4 < 0)
                (void) waddch(stat_w, '-');
        (void) wprintw(stat_w, "Rigg %d %d %d ", mc->rig1, mc->rig2, mc->rig3);
        if (mc->rig4 < 0)
                (void) waddch(stat_w, '-');
@@ -417,3 +468,14 @@ adjustview()
        else if (mf->col > viewcol + (VIEW_X - VIEW_X/8))
                viewcol = mf->col - VIEW_X/8;
 }
        else if (mf->col > viewcol + (VIEW_X - VIEW_X/8))
                viewcol = mf->col - VIEW_X/8;
 }
+
+#ifdef SIGTSTP
+void
+susp()
+{
+       blockalarm();
+       tstp();
+       (void) signal(SIGTSTP, susp);
+       unblockalarm();
+}
+#endif