Get rid of obnoxious visible "have we paused?" state.
authorEric S. Raymond <esr@thyrsus.com>
Thu, 28 Sep 2006 09:19:16 +0000 (09:19 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 28 Sep 2006 09:19:16 +0000 (09:19 +0000)
This change shouldn't make any behavioral difference, but it
simplifies the call sequence and code of a couple of functions.

src/ai.c
src/events.c
src/io.c
src/sst.h
src/sst.py

index 1ea8cfa288b329569b8a69a274067be432084ebc..66b50d7165ded56ef8d606e8f368760c8f96b21b 100644 (file)
--- a/src/ai.c
+++ b/src/ai.c
@@ -307,7 +307,7 @@ void moveklings(void)
     sortkl();
 }
 
-static bool movescom(coord iq, bool flag, bool *ipage
+static bool movescom(coord iq, bool flag) 
 /* commander movement helper */
 {
     int i;
@@ -357,9 +357,7 @@ static bool movescom(coord iq, bool flag, bool *ipage)
            DESTROY(&game.state.planets[i]);
            game.state.galaxy[game.state.kscmdr.x][game.state.kscmdr.y].planet = NOPLANET;
            if (!damaged(DRADIO) || game.condition == docked) {
-               if (!*ipage)
-                   pause_game(true);
-               *ipage = true;
+               pause_game(true);
                prout(_("Lt. Uhura-  \"Captain, Starfleet Intelligence reports"));
                proutn(_("   a planet in "));
                proutn(cramlc(quadrant, game.state.kscmdr));
@@ -372,7 +370,7 @@ static bool movescom(coord iq, bool flag, bool *ipage)
     return false; /* looks good! */
 }
                        
-void scom(bool *ipage)
+void scom(void)
 /* move the Super Commander */
 {
     int i, i2, j, ideltax, ideltay, ifindit, iwhichb;
@@ -472,32 +470,32 @@ void scom(bool *ipage)
     /* try moving in both x and y directions */
     iq.x = game.state.kscmdr.x + ideltax;
     iq.y = game.state.kscmdr.y + ideltax;
-    if (movescom(iq, flag, ipage)) {
+    if (movescom(iq, flag)) {
        /* failed -- try some other maneuvers */
        if (ideltax==0 || ideltay==0) {
            /* attempt angle move */
            if (ideltax != 0) {
                iq.y = game.state.kscmdr.y + 1;
-               if (movescom(iq, flag, ipage)) {
+               if (movescom(iq, flag)) {
                    iq.y = game.state.kscmdr.y - 1;
-                   movescom(iq, flag, ipage);
+                   movescom(iq, flag);
                }
            }
            else {
                iq.x = game.state.kscmdr.x + 1;
-               if (movescom(iq, flag, ipage)) {
+               if (movescom(iq, flag)) {
                    iq.x = game.state.kscmdr.x - 1;
-                   movescom(iq, flag, ipage);
+                   movescom(iq, flag);
                }
            }
        }
        else {
            /* try moving just in x or y */
            iq.y = game.state.kscmdr.y;
-           if (movescom(iq, flag, ipage)) {
+           if (movescom(iq, flag)) {
                iq.y = game.state.kscmdr.y + ideltay;
                iq.x = game.state.kscmdr.x;
-               movescom(iq, flag, ipage);
+               movescom(iq, flag);
            }
        }
     }
@@ -518,9 +516,7 @@ void scom(bool *ipage)
            if (damaged(DRADIO) && game.condition != docked)
                return; /* no warning */
            game.iseenit = true;
-           if (!*ipage)
-               pause_game(true);
-           *ipage = true;
+           pause_game(true);
            proutn(_("Lt. Uhura-  \"Captain, the starbase in "));
            proutn(cramlc(quadrant, game.state.kscmdr));
            skip(1);
@@ -544,9 +540,7 @@ void scom(bool *ipage)
         (damaged(DRADIO) && game.condition != docked) ||
         !game.state.galaxy[game.state.kscmdr.x][game.state.kscmdr.y].charted))
        return;
-    if (!*ipage)
-       pause_game(true);
-    *ipage = true;
+    pause_game(true);
     prout(_("Lt. Uhura-  \"Captain, Starfleet Intelligence reports"));
     proutn(_("   the Super-commander is in "));
     proutn(cramlc(quadrant, game.state.kscmdr));
index 746911a3b9ff60071eb4bb4b16c535ee4df7f325..b82aff7caa9b65addeaf47cdb725b20cf5c64722 100644 (file)
@@ -62,11 +62,13 @@ void events(void)
 {
     int evcode, i=0, j, k, l;
     double fintim = game.state.date + game.optime, datemin, xtime, repair, yank=0;
-    bool radio_was_broken, ictbeam = false, ipage = false, istract = false;
+    bool radio_was_broken, ictbeam = false, istract = false;
     struct quadrant *pdest, *q;
     coord w, hold;
     event *ev, *ev2;
 
+    pause_reset();
+
     if (idebug) {
        prout("=== EVENTS from %.2f to %.2f:", game.state.date, fintim);
        for (i = 1; i < NEVENTS; i++) {
@@ -156,9 +158,7 @@ void events(void)
        game.optime -= xtime;
        switch (evcode) {
        case FSNOVA: /* Supernova */
-           if (!ipage)
-               pause_game(true);
-           ipage=true;
+           pause_game(true);
            snova(false, NULL);
            schedule(FSNOVA, expran(0.5*game.intime));
            if (game.state.galaxy[game.quadrant.x][game.quadrant.y].supernova)
@@ -198,9 +198,7 @@ void events(void)
            }
            /* tractor beaming cases merge here */
            yank = sqrt(yank);
-           if (!ipage)
-               pause_game(true);
-           ipage=true;
+           pause_game(true);
            game.optime = (10.0/(7.5*7.5))*yank; /* 7.5 is yank rate (warp 7.5) */
            ictbeam = true;
            skip(1);
@@ -299,9 +297,7 @@ void events(void)
            if (!damaged(DRADIO) && game.condition != docked) 
                break; /* No warning :-( */
            game.iseenit = true;
-           if (!ipage)
-               pause_game(true);
-           ipage = true;
+           pause_game(true);
            skip(1);
            proutn(_("Lt. Uhura-  \"Captain, the starbase in "));
            prout(cramlc(quadrant, game.battle));
@@ -348,9 +344,7 @@ void events(void)
            else if (game.state.rembase != 1 &&
                     (!damaged(DRADIO) || game.condition == docked)) {
                /* Get word via subspace radio */
-               if (!ipage)
-                   pause_game(true);               
-               ipage = true;
+               pause_game(true);                   
                skip(1);
                prout(_("Lt. Uhura-  \"Captain, Starfleet Command reports that"));
                proutn(_("   the starbase in "));
@@ -380,7 +374,7 @@ void events(void)
            schedule(FSCMOVE, 0.2777);
            if (!game.ientesc && !istract && game.isatb != 1 &&
                        (!game.iscate || !game.justin)) 
-               scom(&ipage);
+               scom();
            break;
        case FDSPROB: /* Move deep space probe */
            schedule(FDSPROB, 0.01);
@@ -395,9 +389,7 @@ void events(void)
                    game.state.galaxy[game.probec.x][game.probec.y].supernova) {
                    // Left galaxy or ran into supernova
                    if (!damaged(DRADIO) || game.condition == docked) {
-                       if (!ipage)
-                           pause_game(true);
-                       ipage = true;
+                       pause_game(true);
                        skip(1);
                        proutn(_("Lt. Uhura-  \"The deep space probe "));
                        if (!VALID_QUADRANT(j, i))
@@ -410,9 +402,7 @@ void events(void)
                    break;
                }
                if (!damaged(DRADIO) || game.condition == docked) {
-                   if (!ipage)
-                       pause_game(true);
-                   ipage = true;
+                   pause_game(true);
                    skip(1);
                    proutn(_("Lt. Uhura-  \"The deep space probe is now in "));
                    proutn(cramlc(quadrant, game.probec));
index c0867fbc9577d21717e02c094b6458d5d669e72a..80aa0759859c9a5613d465c8fa52f0ee19d8d04a 100644 (file)
--- a/src/io.c
+++ b/src/io.c
@@ -7,6 +7,7 @@
 #include "sstlinux.h"
 
 static int rows, linecount;    /* for paging */
+static bool pause_latch;
 
 WINDOW *curwnd;
 WINDOW *fullscreen_window;
@@ -89,42 +90,52 @@ void waitfor(void)
        getch();
 }
 
+void pause_reset(void)
+{
+    pause_latch = false;
+}
+
 void pause_game(bool announcement) 
 {
-    char *prompt;
-    char buf[BUFSIZ];
-    if (announcement) {
-       if (game.skill > SKILL_FAIR)
-           prompt = _("[ANOUNCEMENT ARRIVING...]");
-       else
-           prompt = _("[IMPORTANT ANNOUNCEMENT ARRIVING -- PRESS ENTER TO CONTINUE]");
-    }
+    if (pause_latch)
+       return;
     else {
-       if (game.skill > SKILL_FAIR)
-           prompt = _("[CONTINUE?]");
-       else
-           prompt = _("[PRESS ENTER TO CONTINUE]");
-
-    }
-    if (game.options & OPTION_CURSES) {
-       drawmaps(0);
-       setwnd(prompt_window);
-       wclear(prompt_window);
-       waddstr(prompt_window, prompt);
-       wgetnstr(prompt_window, buf, sizeof(buf));
-       wclear(prompt_window);
-       wrefresh(prompt_window);
-       setwnd(message_window);
-    } else {
-       putchar('\n');
-       proutn(prompt);
-       fgets(buf, sizeof(buf), stdin);
+       char *prompt;
+       char buf[BUFSIZ];
        if (announcement) {
-           int j;
-           for (j = 0; j < rows; j++)
-               putchar('\n');
+           if (game.skill > SKILL_FAIR)
+               prompt = _("[ANOUNCEMENT ARRIVING...]");
+           else
+               prompt = _("[IMPORTANT ANNOUNCEMENT ARRIVING -- PRESS ENTER TO CONTINUE]");
+       }
+       else {
+           if (game.skill > SKILL_FAIR)
+               prompt = _("[CONTINUE?]");
+           else
+               prompt = _("[PRESS ENTER TO CONTINUE]");
+
+       }
+       if (game.options & OPTION_CURSES) {
+           drawmaps(0);
+           setwnd(prompt_window);
+           wclear(prompt_window);
+           waddstr(prompt_window, prompt);
+           wgetnstr(prompt_window, buf, sizeof(buf));
+           wclear(prompt_window);
+           wrefresh(prompt_window);
+           setwnd(message_window);
+       } else {
+           putchar('\n');
+           proutn(prompt);
+           fgets(buf, sizeof(buf), stdin);
+           if (announcement) {
+               int j;
+               for (j = 0; j < rows; j++)
+                   putchar('\n');
+           }
+           linecount = 0;
        }
-       linecount = 0;
+       pause_latch = true;
     }
 }
 
index ce4c6792e345dd260de57a7dea7e67290af92901..2dbb50c14f190dd894f6fede1a00c9155eb11eef 100644 (file)
--- a/src/sst.h
+++ b/src/sst.h
@@ -406,10 +406,11 @@ void timwrp(void);
 void moveklings(void);
 void torpedo(double, double, coord, double *, int, int);
 void huh(void);
+void pause_reset(void);
 void pause_game(bool);
 void nova(coord);
 void snova(bool, coord *);
-void scom(bool *);
+void scom(void);
 void hittem(double *);
 bool isit(char *);
 void preport(void);
index 2ad02411b701b35920fc09269cd8872a03fbbf4f..ace9641c7da650a38076089c0f05ba4c97016f96 100644 (file)
@@ -544,7 +544,6 @@ def moveklings():
 
 def movescom(ship, avoid):
     # commander movement helper
-    global ipage
     if game.state.kscmdr == game.quadrant or \
        game.state.galaxy[iq].supernova or \
         game.state.galaxy[iq].klingons > MAXKLQUAD-1: 
@@ -575,9 +574,7 @@ def movescom(ship, avoid):
            # destroy the planet
            del planet
             if communicating():
-                if not ipage:
                     pause_game(True)
-               ipage = true
                prout("Lt. Uhura-  \"Captain, Starfleet Intelligence reports")
                proutn(_("   a planet in "))
                proutn(cramlc(quadrant, game.state.kscmdr))
@@ -669,9 +666,7 @@ def scom():
                 if not communicating():
                     return # no warning
                 game.iseenit = True
-                if not ipage:
-                    pause_game(true)
-                ipage = True
+                pause_game(true)
                 proutn(_("Lt. Uhura-  \"Captain, the starbase in "))
                 proutn(cramlc(quadrant, game.state.kscmdr))
                 skip(1)
@@ -690,9 +685,7 @@ def scom():
     if (Rand() > 0.2 or not communicating() or
         not game.state.galaxy[game.state.kscmdr].charted):
        return
-    if ipage:
-        pause_game(true)
-        ipage = true
+    pause_game(true)
     prout(_("Lt. Uhura-  \"Captain, Starfleet Intelligence reports"))
     proutn(_("   the Super-commander is in "))
     proutn(cramlc(quadrant, game.state.kscmdr))