15 static int linecount; /* for paging */
17 static int screenheight = 24, screenwidth = 80;
19 static int curses = FALSE;
21 static int curses = TRUE;
25 wnd wnds[6]={{1,1,80,25}, /* FULLSCREEN_WINDOW */
26 {1,1,25,12}, /* LEFTUPPER_WINDOW */
27 {26,2,80,12}, /* SRSCAN_WINDOW */
28 {65,1,80,10}, /* LRSCAN_WINDOW */
29 {1,13,80,23}, /* LOWER_WINDOW */
30 {1,24,80,25}, /* BOTTOM_WINDOW */
35 static void outro(int sig) {
36 /* wrap up, either normally or due to signal */
46 static void fastexit(int sig) {
52 void iostart(int usecurses) {
56 setwnd(FULLSCREEN_WINDOW);
58 (void) signal(SIGINT, fastexit);
59 (void) signal(SIGINT, fastexit);
61 (void) signal(SIGIOT,fastexit); /* for assert(3) */
63 if(signal(SIGQUIT,SIG_IGN) != SIG_IGN)
64 (void)signal(SIGQUIT,fastexit);
66 if ((curses = usecurses)) {
75 scrollok(stdscr, TRUE);
76 getmaxyx(stdscr, screenheight, screenwidth);
78 char *LINES = getenv("LINES");
80 screenheight = atoi(LINES);
92 /* wait for user action -- OK to do nothing if on a TTY */
98 void pause_game(int i) {
104 setwnd(BOTTOM_WINDOW);
108 prompt = "[ANOUNCEMENT ARRIVING...]";
110 prompt = "[IMPORTANT ANNOUNCEMENT ARRIVING -- PRESS ENTER TO CONTINUE]";
114 prompt = "[CONTINUE?]";
116 prompt = "[PRESS ENTER TO CONTINUE]";
121 waddch(stdscr, '\n');
122 waddstr(stdscr, prompt);
123 wgetnstr(stdscr, buf, sizeof(buf));
129 fgets(buf, sizeof(buf), stdin);
131 /* much more in that old-TTY spirit to throw linefeeds */
133 for (j = 0; j < screenheight; j++)
142 setwnd(LOWER_WINDOW);
154 if (y == screenheight-1)
157 waddch(stdscr, '\n');
160 if (linecount >= screenheight)
166 while (i-- > 0) proutn("\n\r");
169 static void vproutn(char *fmt, va_list ap) {
171 vasprintf(&s, fmt, ap);
173 if ((curwnd==LOWER_WINDOW)&&(wherey()==wnds[curwnd].wndbottom-wnds[curwnd].wndtop)){
174 if (strchr(s,'\n')) {
184 if ((curwnd==LOWER_WINDOW)&&(wherey()>wnds[curwnd].wndbottom-wnds[curwnd].wndtop+1))
187 if (strchr(s,'\n') || strchr(s,'\r')) clreol();
193 void proutn(char *fmt, ...) {
198 vw_printw(stdscr, fmt, ap);
208 void prout(char *fmt, ...) {
213 vw_printw(stdscr, fmt, ap);
224 void proutc(char *line) {
225 line[strlen(line)-1] = '\0';
228 waddstr(stdscr, line);
238 static void prchr(char *s){
245 static void vprouts(char *fmt, va_list ap) {
247 vasprintf(&s, fmt, ap);
257 void prouts(char *fmt, ...) {
260 char *s, buf[BUFSIZ];
264 vsprintf(buf, fmt, ap);
267 for (s = buf; *s; s++) {
268 endTime = clock() + CLOCKS_PER_SEC*0.05;
269 while (clock() < endTime) continue;
287 void c_printf (char *format, ... )
289 char buffer[BUFSIZ]; /* Well, BUFSIZ is from ncurses... */
291 va_start(argp,format);
292 vsprintf(buffer,format,argp);
295 waddstr(conio_scr,buffer);
301 void cgetline(char *line, int max) {
304 wgetnstr(stdscr, line, max);
309 memmove(line,&line[2],max-3);
312 fgets(line, max, stdin);
313 line[strlen(line)-1] = '\0';
317 void setwnd(short wndnum){
318 /* change windows -- OK for this to be a no-op in tty mode */
321 cury=wherey()+wnds[curwnd].wndtop-wnds[wndnum].wndtop;
322 if ((curwnd==FULLSCREEN_WINDOW)&&(wndnum!=FULLSCREEN_WINDOW)) clrscr();
323 window(wnds[wndnum].wndleft, wnds[wndnum].wndtop, wnds[wndnum].wndright, wnds[wndnum].wndbottom);
324 if ((curwnd==wndnum)&&(cury>wnds[wndnum].wndbottom-wnds[wndnum].wndtop+1)){
325 gotoxy(wnds[wndnum].wndright-wnds[wndnum].wndleft+1,wnds[wndnum].wndbottom-wnds[wndnum].wndtop+1);
333 void commandhook(char *cmd, int before) {
337 * Things past this point have policy implications.
340 void drawmaps(short l) {
341 /* hook to be called after moving to redraw maps */
343 _setcursortype(_NOCURSOR);
345 if (l!=2) setwnd(LEFTUPPER_WINDOW);
350 setwnd(SRSCAN_WINDOW);
353 setwnd(LRSCAN_WINDOW);
357 _setcursortype(_NORMALCURSOR);
362 void boom(int ii, int jj)
363 /* enemy fall down, go boom */
369 setwnd(LEFTUPPER_WINDOW);
373 proutn("%c", game.quad[ii][jj]);
374 gotoxy(wherex()-1,wherey());
379 proutn("%c", game.quad[ii][jj]);
380 setwnd(LOWER_WINDOW);
382 _setcursortype(_NORMALCURSOR);
388 /* sound and visual effects for teleportation */
395 setwnd(LOWER_WINDOW);
401 prouts(" . . . . . ");
405 void tracktorpedo(int x, int y, int ix, int iy, int wait, int l, int i, int n, int iquad)
406 /* torpedo-track animation */
412 proutn("Track for torpedo number %d- ", i);
416 proutn("Torpedo track- ");
418 } else if (l==4 || l==9)
420 proutn("%d - %d ", (int)x, (int)y);
422 if (game.damage[DSRSENS]==0 || condit==IHDOCKED) {
424 delay((wait!=1)*400);
426 if ((game.quad[ix][iy]==IHDOT)||(game.quad[ix][iy]==IHBLANK)){
427 game.quad[ix][iy]='+';
429 game.quad[ix][iy]=iquad;
435 game.quad[ix][iy]|=128;
437 game.quad[ix][iy]=iquad;
438 _setcursortype(_NOCURSOR);
443 _setcursortype(_NORMALCURSOR);
446 proutn("%d - %d ", (int)x, (int)y);
451 void makechart(void) {
453 _setcursortype(_NOCURSOR);
454 setwnd(LOWER_WINDOW);
457 _setcursortype(_NORMALCURSOR);
461 void setpassword(void) {
465 strcpy(game.passwd, citem);
467 if (*game.passwd != 0) break;
468 proutn("Please type in a secret password-");
472 for(i=0;i<3;i++) game.passwd[i]=(char)(97+(int)(Rand()*25));