From 9aef5f5aae5fde0ed2b462945750c7aee59b3c1e Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Thu, 28 Sep 2006 09:19:16 +0000 Subject: [PATCH] Get rid of obnoxious visible "have we paused?" state. This change shouldn't make any behavioral difference, but it simplifies the call sequence and code of a couple of functions. --- src/ai.c | 30 +++++++++------------ src/events.c | 30 +++++++-------------- src/io.c | 73 ++++++++++++++++++++++++++++++---------------------- src/sst.h | 3 ++- src/sst.py | 11 ++------ 5 files changed, 68 insertions(+), 79 deletions(-) diff --git a/src/ai.c b/src/ai.c index 1ea8cfa..66b50d7 100644 --- 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)); diff --git a/src/events.c b/src/events.c index 746911a..b82aff7 100644 --- a/src/events.c +++ b/src/events.c @@ -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)); diff --git a/src/io.c b/src/io.c index c0867fb..80aa075 100644 --- 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; } } diff --git a/src/sst.h b/src/sst.h index ce4c679..2dbb50c 100644 --- 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); diff --git a/src/sst.py b/src/sst.py index 2ad0241..ace9641 100644 --- a/src/sst.py +++ b/src/sst.py @@ -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)) -- 2.31.1