X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=blobdiff_plain;f=src%2Fio.c;h=80aa0759859c9a5613d465c8fa52f0ee19d8d04a;hp=b60fec51645f9d8ba8c597c14e63e28677f1814c;hb=9aef5f5aae5fde0ed2b462945750c7aee59b3c1e;hpb=6332f1c7917206e23f408ebb505c483416b84e5b diff --git a/src/io.c b/src/io.c index b60fec5..80aa075 100644 --- a/src/io.c +++ b/src/io.c @@ -1,16 +1,19 @@ #include #include +#include #include "config.h" #include "sst.h" #include "sstlinux.h" static int rows, linecount; /* for paging */ +static bool pause_latch; WINDOW *curwnd; WINDOW *fullscreen_window; WINDOW *srscan_window; WINDOW *report_window; +WINDOW *status_window; WINDOW *lrscan_window; WINDOW *message_window; WINDOW *prompt_window; @@ -19,12 +22,12 @@ static void outro(void) /* wrap up, either normally or due to signal */ { if (game.options & OPTION_CURSES) { - clear(); - curs_set(1); - (void)refresh(); - (void)resetterm(); - //(void)echo(); - (void)endwin(); + //clear(); + //curs_set(1); + //refresh(); + //resetterm(); + //echo(); + endwin(); putchar('\n'); } if (logfp) @@ -42,15 +45,16 @@ void iostart(void) exit(1); } if (!(game.options & OPTION_CURSES)) { - rows = atoi(getenv("LINES")); + char *ln_env = getenv("LINES"); + rows = ln_env ? atoi(ln_env) : 25; } else { - (void)initscr(); + initscr(); #ifdef KEY_MIN keypad(stdscr, TRUE); #endif /* KEY_MIN */ - (void)saveterm(); - (void)nonl(); - (void)cbreak(); + saveterm(); + nonl(); + cbreak(); #ifdef A_COLOR { start_color(); @@ -64,11 +68,12 @@ void iostart(void) init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK); } #endif /* A_COLOR */ - //(void)noecho(); + //noecho(); fullscreen_window = stdscr; srscan_window = newwin(12, 25, 0, 0); - report_window = newwin(10, 0, 1, 25); - lrscan_window = newwin(10, 0, 0, 64); + report_window = newwin(11, 0, 1, 25); + status_window = newwin(10, 0, 1, 39); + lrscan_window = newwin(5, 0, 0, 64); message_window = newwin(0, 0, 12, 0); prompt_window = newwin(1, 0, LINES-2, 0); scrollok(message_window, TRUE); @@ -85,42 +90,52 @@ void waitfor(void) getch(); } -void pause_game(int i) +void pause_reset(void) { - char *prompt; - char buf[BUFSIZ]; - if (i==1) { - if (game.skill > SKILL_FAIR) - prompt = _("[ANOUNCEMENT ARRIVING...]"); - else - prompt = _("[IMPORTANT ANNOUNCEMENT ARRIVING -- PRESS ENTER TO CONTINUE]"); - } + pause_latch = false; +} + +void pause_game(bool announcement) +{ + if (pause_latch) + return; else { - if (game.skill > SKILL_FAIR) - prompt = _("[CONTINUE?]"); - else - prompt = _("[PRESS ENTER TO CONTINUE]"); + char *prompt; + char buf[BUFSIZ]; + if (announcement) { + 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 (i != 0) { - int j; - for (j = 0; j < rows; j++) - putchar('\n'); } - linecount = 0; + 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; + } + pause_latch = true; } } @@ -129,25 +144,23 @@ void skip(int i) { while (i-- > 0) { if (game.options & OPTION_CURSES) { - if (curwnd == message_window && linecount >= getmaxy(curwnd) - 3) { - pause_game(0); + if (curwnd == message_window && getcury(curwnd) >= getmaxy(curwnd) - 3) { + pause_game(false); clrscr(); } else { proutn("\n"); - if (curwnd == message_window) - linecount++; } } else { linecount++; if (linecount >= rows) - pause_game(0); + pause_game(false); else putchar('\n'); } } } -static void vproutn(char *fmt, va_list ap) +static void vproutn(const char *fmt, va_list ap) { if (game.options & OPTION_CURSES) { vwprintw(curwnd, fmt, ap); @@ -157,7 +170,7 @@ static void vproutn(char *fmt, va_list ap) vprintf(fmt, ap); } -void proutn(char *fmt, ...) +void proutn(const char *fmt, ...) { va_list ap; va_start(ap, fmt); @@ -165,7 +178,7 @@ void proutn(char *fmt, ...) va_end(ap); } -void prout(char *fmt, ...) +void prout(const char *fmt, ...) { va_list ap; va_start(ap, fmt); @@ -174,25 +187,32 @@ void prout(char *fmt, ...) skip(1); } -void prouts(char *fmt, ...) +void prouts(const char *fmt, ...) /* print slowly! */ { - char *s, buf[BUFSIZ]; + char buf[BUFSIZ]; + wchar_t *s, mbuf[BUFSIZ]; va_list ap; va_start(ap, fmt); vsprintf(buf, fmt, ap); va_end(ap); - for (s = buf; *s; s++) { + mbstowcs(mbuf, buf, BUFSIZ); + for (s = mbuf; *s; s++) { + /* HOW to convince ncurses to use wchar_t?? */ + /* WHY putwchar() doesn't work?? */ + /* OK then, convert back to mbs... */ + char c[MB_CUR_MAX*2]; + int n; + n = wctomb(c, *s); + c[n] = 0; delay(30); - if (game.options & OPTION_CURSES) { - waddch(curwnd, *s); + proutn(c); + if (game.options & OPTION_CURSES) wrefresh(curwnd); - } - else { - putchar(*s); + else fflush(stdout); - } } + delay(300); } void cgetline(char *line, int max) @@ -221,7 +241,7 @@ void setwnd(WINDOW *wnd) } } -void clreol (void) +void clreol(void) /* clear to end of line -- can be a no-op in tty mode */ { if (game.options & OPTION_CURSES) { @@ -230,7 +250,7 @@ void clreol (void) } } -void clrscr (void) +void clrscr(void) /* clear screen -- can be a no-op in tty mode */ { if (game.options & OPTION_CURSES) { @@ -241,7 +261,7 @@ void clrscr (void) linecount = 0; } -void textcolor (int color) +void textcolor(int color) { #ifdef A_COLOR if (game.options & OPTION_CURSES) { @@ -302,7 +322,7 @@ void textcolor (int color) #endif /* A_COLOR */ } -void highvideo (void) +void highvideo(void) { if (game.options & OPTION_CURSES) { wattron(curwnd, A_REVERSE); @@ -324,17 +344,18 @@ void drawmaps(int mode) sensor(); setwnd(srscan_window); wmove(curwnd, 0, 0); - enqueue("no"); - srscan(SCAN_FULL); + srscan(); if (mode != 2) { + setwnd(status_window); + wclear(status_window); + wmove(status_window, 0, 0); setwnd(report_window); wclear(report_window); wmove(report_window, 0, 0); - srscan(SCAN_NO_LEFTSIDE); + status(0); setwnd(lrscan_window); wclear(lrscan_window); wmove(lrscan_window, 0, 0); - enqueue("l"); lrscan(); } } @@ -397,7 +418,7 @@ void tracktorpedo(coord w, int l, int i, int n, int iquad) skip(1); proutn("%d - %d ", w.x, w.y); } else { - if (!damaged(DSRSENS) || game.condit==IHDOCKED) { + if (!damaged(DSRSENS) || game.condition==docked) { if (i != 1 && l == 1) { drawmaps(2); delay(400); @@ -429,6 +450,31 @@ void makechart(void) if (game.options & OPTION_CURSES) { setwnd(message_window); wclear(message_window); - chart(false); } + chart(); + if (game.options & OPTION_TTY) { + skip(1); + } +} + +void prstat(const char *txt, const char *fmt, ...) +{ +#define NSYM 14 + int i; + va_list args; + proutn(txt); + if (game.options & OPTION_CURSES) { + skip(1); + } else { + for (i = mblen(txt, strlen(txt)); i < NSYM; i++) + proutn(" "); + } + if (game.options & OPTION_CURSES) + setwnd(status_window); + va_start(args, fmt); + vproutn(fmt, args); + va_end(args); + skip(1); + if (game.options & OPTION_CURSES) + setwnd(report_window); }