X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=blobdiff_plain;f=src%2Fio.c;h=6c312bf2aed4729023ec36e73ecc2364b11bd579;hp=e218c3ee7d2fc191624a7d092262969adb2e36a9;hb=29d86fb395ca01e4a4f65f02d67f5823a4ebba11;hpb=ad6b6f3e8316dc43c8f80ca8bc57be091b0076c6 diff --git a/src/io.c b/src/io.c index e218c3e..6c312bf 100644 --- a/src/io.c +++ b/src/io.c @@ -1,5 +1,6 @@ #include #include +#include #include "config.h" #include "sst.h" @@ -11,6 +12,7 @@ WINDOW *curwnd; WINDOW *fullscreen_window; WINDOW *srscan_window; WINDOW *report_window; +WINDOW *status_window; WINDOW *lrscan_window; WINDOW *message_window; WINDOW *prompt_window; @@ -42,15 +44,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 +67,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); @@ -82,46 +86,43 @@ void waitfor(void) /* wait for user action -- OK to do nothing if on a TTY */ { if (game.options & OPTION_CURSES) - getch(); + wgetch(prompt_window); } -void pause_game(bool announcement) +void announce(void) { - 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) + skip(1); + prouts(_("[ANOUNCEMENT ARRIVING...]")); + skip(1); +} + +static void pause_game(void) +{ + char *prompt; + char buf[BUFSIZ]; + 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) { + 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 { int j; + putchar('\n'); + proutn(prompt); + fgets(buf, sizeof(buf), stdin); for (j = 0; j < rows; j++) putchar('\n'); + linecount = 0; } - linecount = 0; - } } @@ -129,25 +130,23 @@ void skip(int i) { while (i-- > 0) { if (game.options & OPTION_CURSES) { - if (curwnd == message_window && linecount >= getmaxy(curwnd) - 3) { - pause_game(false); + if (curwnd == message_window && getcury(curwnd) >= getmaxy(curwnd) - 3) { + pause_game(); clrscr(); } else { proutn("\n"); - if (curwnd == message_window) - linecount++; } } else { linecount++; if (linecount >= rows) - pause_game(false); + pause_game(); 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 +156,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 +164,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 +173,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 +227,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 +236,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 +247,7 @@ void clrscr (void) linecount = 0; } -void textcolor (int color) +void textcolor(int color) { #ifdef A_COLOR if (game.options & OPTION_CURSES) { @@ -302,7 +308,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 +330,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(); } } @@ -429,6 +436,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); }