16 static int linecount; /* for paging */
17 static int screenheight = 24, screenwidth = 80;
20 static int curses = FALSE;
22 static int curses = TRUE;
26 wnd wnds[6]={{1,1,80,25}, /* FULLSCREEN_WINDOW */
27 {1,1,25,12}, /* LEFTUPPER_WINDOW */
28 {26,2,80,12}, /* SRSCAN_WINDOW */
29 {65,1,80,10}, /* LRSCAN_WINDOW */
30 {1,13,80,23}, /* LOWER_WINDOW */
31 {1,24,80,25}, /* BOTTOM_WINDOW */
37 static void outro(int sig) {
38 /* wrap up, either normally or due to signal */
48 static void fastexit(int sig) {
55 void iostart(int usecurses) {
59 setwnd(FULLSCREEN_WINDOW);
61 (void) signal(SIGINT, fastexit);
62 (void) signal(SIGINT, fastexit);
64 (void) signal(SIGIOT,fastexit); /* for assert(3) */
66 if(signal(SIGQUIT,SIG_IGN) != SIG_IGN)
67 (void)signal(SIGQUIT,fastexit);
69 if ((curses = usecurses)) {
78 scrollok(stdscr, TRUE);
79 getmaxyx(stdscr, screenheight, screenwidth);
81 char *LINES = getenv("LINES");
83 screenheight = atoi(LINES);
95 /* wait for user action -- OK to do nothing if on a TTY */
101 void pause_game(int i) {
107 setwnd(BOTTOM_WINDOW);
111 prompt = "[ANOUNCEMENT ARRIVING...]";
113 prompt = "[IMPORTANT ANNOUNCEMENT ARRIVING -- PRESS ENTER TO CONTINUE]";
117 prompt = "[CONTINUE?]";
119 prompt = "[PRESS ENTER TO CONTINUE]";
124 waddch(stdscr, '\n');
125 waddstr(stdscr, prompt);
126 wgetnstr(stdscr, buf, sizeof(buf));
132 fgets(buf, sizeof(buf), stdin);
134 /* much more in that old-TTY spirit to throw linefeeds */
136 for (j = 0; j < screenheight; j++)
145 setwnd(LOWER_WINDOW);
157 if (y == screenheight-1)
160 waddch(stdscr, '\n');
163 if (linecount >= screenheight)
169 while (i-- > 0) proutn("\n\r");
173 static void vproutn(char *fmt, va_list ap) {
176 vasprintf(&s, fmt, ap);
178 if ((curwnd==LOWER_WINDOW)&&(wherey()==wnds[curwnd].wndbottom-wnds[curwnd].wndtop)){
179 if (strchr(s,'\n')) {
189 if ((curwnd==LOWER_WINDOW)&&(wherey()>wnds[curwnd].wndbottom-wnds[curwnd].wndtop+1))
192 if (strchr(s,'\n') || strchr(s,'\r')) clreol();
198 void proutn(char *fmt, ...) {
203 vw_printw(stdscr, fmt, ap);
213 void prout(char *fmt, ...) {
218 vw_printw(stdscr, fmt, ap);
229 void proutc(char *line) {
230 line[strlen(line)-1] = '\0';
233 waddstr(stdscr, line);
243 static void prchr(char *s){
250 static void vprouts(char *fmt, va_list ap) {
252 vasprintf(&s, fmt, ap);
262 void prouts(char *fmt, ...) {
265 char *s, buf[BUFSIZ];
269 vsprintf(buf, fmt, ap);
272 for (s = buf; *s; s++) {
273 endTime = clock() + CLOCKS_PER_SEC*0.05;
274 while (clock() < endTime) continue;
292 void c_printf (char *format, ... )
294 char buffer[BUFSIZ]; /* Well, BUFSIZ is from ncurses... */
296 va_start(argp,format);
297 vsprintf(buffer,format,argp);
300 waddstr(conio_scr,buffer);
306 void cgetline(char *line, int max) {
309 wgetnstr(stdscr, line, max);
314 memmove(line,&line[2],max-3);
317 fgets(line, max, stdin);
318 line[strlen(line)-1] = '\0';
322 void setwnd(short wndnum){
323 /* change windows -- OK for this to be a no-op in tty mode */
326 cury=wherey()+wnds[curwnd].wndtop-wnds[wndnum].wndtop;
327 if ((curwnd==FULLSCREEN_WINDOW)&&(wndnum!=FULLSCREEN_WINDOW)) clrscr();
328 window(wnds[wndnum].wndleft, wnds[wndnum].wndtop, wnds[wndnum].wndright, wnds[wndnum].wndbottom);
329 if ((curwnd==wndnum)&&(cury>wnds[wndnum].wndbottom-wnds[wndnum].wndtop+1)){
330 gotoxy(wnds[wndnum].wndright-wnds[wndnum].wndleft+1,wnds[wndnum].wndbottom-wnds[wndnum].wndtop+1);
338 void commandhook(char *cmd, int before) {
342 * Things past this point have policy implications.
345 void drawmaps(short l) {
346 /* hook to be called after moving to redraw maps */
348 _setcursortype(_NOCURSOR);
350 if (l!=2) setwnd(LEFTUPPER_WINDOW);
355 setwnd(SRSCAN_WINDOW);
358 setwnd(LRSCAN_WINDOW);
362 _setcursortype(_NORMALCURSOR);
367 void boom(int ii, int jj)
368 /* enemy fall down, go boom */
374 setwnd(LEFTUPPER_WINDOW);
378 proutn("%c", game.quad[ii][jj]);
379 gotoxy(wherex()-1,wherey());
384 proutn("%c", game.quad[ii][jj]);
385 setwnd(LOWER_WINDOW);
387 _setcursortype(_NORMALCURSOR);
393 /* sound and visual effects for teleportation */
400 setwnd(LOWER_WINDOW);
406 prouts(" . . . . . ");
410 void tracktorpedo(int x, int y, int ix, int iy, int wait, int l, int i, int n, int iquad)
411 /* torpedo-track animation */
417 proutn("Track for torpedo number %d- ", i);
421 proutn("Torpedo track- ");
423 } else if (l==4 || l==9)
425 proutn("%d - %d ", (int)x, (int)y);
427 if (game.damage[DSRSENS]==0 || condit==IHDOCKED) {
429 delay((wait!=1)*400);
431 if ((game.quad[ix][iy]==IHDOT)||(game.quad[ix][iy]==IHBLANK)){
432 game.quad[ix][iy]='+';
434 game.quad[ix][iy]=iquad;
440 game.quad[ix][iy]|=128;
442 game.quad[ix][iy]=iquad;
443 _setcursortype(_NOCURSOR);
448 _setcursortype(_NORMALCURSOR);
451 proutn("%d - %d ", (int)x, (int)y);
456 void makechart(void) {
458 _setcursortype(_NOCURSOR);
459 setwnd(LOWER_WINDOW);
462 _setcursortype(_NORMALCURSOR);
466 void setpassword(void) {
470 strcpy(game.passwd, citem);
472 if (*game.passwd != 0) break;
473 proutn("Please type in a secret password-");
477 for(i=0;i<3;i++) game.passwd[i]=(char)(97+(int)(Rand()*25));