X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=blobdiff_plain;f=src%2Fio.c;h=6c312bf2aed4729023ec36e73ecc2364b11bd579;hp=5c5ac644526dc4c91ba5f9db6be3e20b04fab22f;hb=29d86fb395ca01e4a4f65f02d67f5823a4ebba11;hpb=ebc4fdc3802c47c9fe7ec31b4cde062faff366fc diff --git a/src/io.c b/src/io.c index 5c5ac64..6c312bf 100644 --- a/src/io.c +++ b/src/io.c @@ -1,10 +1,8 @@ #include #include -#include -#include -#include -#include +#include +#include "config.h" #include "sst.h" #include "sstlinux.h" @@ -14,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; @@ -22,32 +21,39 @@ 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) + fclose(logfp); } void iostart(void) { + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + + if (atexit(outro)){ + fprintf(stderr,"Unable to register outro(), exiting...\n"); + exit(1); + } if (!(game.options & OPTION_CURSES)) { - rows = atoi(getenv("LINES")); + char *ln_env = getenv("LINES"); + rows = ln_env ? atoi(ln_env) : 25; } else { - if (atexit(outro)){ - fprintf(stderr,"Unable to register outro(), exiting...\n"); - exit(1); - } - (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(); @@ -61,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); @@ -79,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(int i) +void announce(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]"; - } - else { - if (game.skill > SKILL_FAIR) - prompt = "[CONTINUE?]"; + 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]"; + 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) { + 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; - } } @@ -126,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(0); + 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(0); + 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); @@ -154,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); @@ -162,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); @@ -171,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) @@ -199,8 +208,13 @@ void cgetline(char *line, int max) strcat(line, "\n"); wrefresh(curwnd); } else { - fgets(line, max, stdin); + if (replayfp && !feof(replayfp)) + fgets(line, max, replayfp); + else + fgets(line, max, stdin); } + if (logfp) + fputs(line, logfp); line[strlen(line)-1] = '\0'; } @@ -213,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) { @@ -222,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) { @@ -233,7 +247,7 @@ void clrscr (void) linecount = 0; } -void textcolor (int color) +void textcolor(int color) { #ifdef A_COLOR if (game.options & OPTION_CURSES) { @@ -294,64 +308,65 @@ void textcolor (int color) #endif /* A_COLOR */ } -void highvideo (void) +void highvideo(void) { if (game.options & OPTION_CURSES) { wattron(curwnd, A_REVERSE); } } -void commandhook(char *cmd, int before) { +void commandhook(char *cmd, bool before) { } /* * Things past this point have policy implications. */ -void drawmaps(short l) +void drawmaps(int mode) /* hook to be called after moving to redraw maps */ { if (game.options & OPTION_CURSES) { - if (l == 1) + if (mode == 1) sensor(); setwnd(srscan_window); wmove(curwnd, 0, 0); - enqueue("no"); - srscan(SCAN_FULL); - if (l != 2) { + 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(); } } } -static void put_srscan_sym(int x, int y, char sym) +static void put_srscan_sym(coord w, char sym) { - wmove(srscan_window, x+1, y*2+2); + wmove(srscan_window, w.x+1, w.y*2+2); waddch(srscan_window, sym); wrefresh(srscan_window); } -void boom(int ii, int jj) +void boom(coord w) /* enemy fall down, go boom */ { if (game.options & OPTION_CURSES) { drawmaps(2); setwnd(srscan_window); wattron(srscan_window, A_REVERSE); - put_srscan_sym(ii, jj, game.quad[ii][jj]); + put_srscan_sym(w, game.quad[w.x][w.y]); sound(500); delay(1000); nosound(); wattroff(srscan_window, A_REVERSE); - put_srscan_sym(ii, jj, game.quad[ii][jj]); + put_srscan_sym(w, game.quad[w.x][w.y]); delay(500); setwnd(message_window); } @@ -372,46 +387,46 @@ void warble(void) } } -void tracktorpedo(int ix, int iy, int l, int i, int n, int iquad) +void tracktorpedo(coord w, int l, int i, int n, int iquad) /* torpedo-track animation */ { if (!game.options & OPTION_CURSES) { if (l == 1) { if (n != 1) { skip(1); - proutn("Track for torpedo number %d- ", i); + proutn(_("Track for torpedo number %d- "), i); } else { skip(1); - proutn("Torpedo track- "); + proutn(_("Torpedo track- ")); } } else if (l==4 || l==9) skip(1); - proutn("%d - %d ", ix, iy); + proutn("%d - %d ", w.x, w.y); } else { - if (game.damage[DSRSENS]==0 || game.condit==IHDOCKED) { + if (!damaged(DSRSENS) || game.condition==docked) { if (i != 1 && l == 1) { drawmaps(2); delay(400); } if ((iquad==IHDOT)||(iquad==IHBLANK)){ - put_srscan_sym(ix, iy, '+'); + put_srscan_sym(w, '+'); sound(l*10); delay(100); nosound(); - put_srscan_sym(ix, iy, iquad); + put_srscan_sym(w, iquad); } else { wattron(curwnd, A_REVERSE); - put_srscan_sym(ix, iy, iquad); + put_srscan_sym(w, iquad); sound(500); delay(1000); nosound(); wattroff(curwnd, A_REVERSE); - put_srscan_sym(ix, iy, iquad); + put_srscan_sym(w, iquad); } } else { - proutn("%d - %d ", ix, iy); + proutn("%d - %d ", w.x, w.y); } } } @@ -421,24 +436,31 @@ void makechart(void) if (game.options & OPTION_CURSES) { setwnd(message_window); wclear(message_window); - chart(0); + } + chart(); + if (game.options & OPTION_TTY) { + skip(1); } } -void setpassword(void) +void prstat(const char *txt, const char *fmt, ...) { - if (!(game.options & OPTION_CURSES)) { - while (TRUE) { - scan(); - strcpy(game.passwd, citem); - chew(); - if (*game.passwd != 0) break; - proutn("Please type in a secret password-"); - } - } else { - int i; - for(i=0;i<3;i++) game.passwd[i]=(char)(97+(int)(Rand()*25)); - game.passwd[3]=0; +#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); } -