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");
170 static void vproutn(char *fmt, va_list ap) {
173 vasprintf(&s, fmt, ap);
175 if ((curwnd==LOWER_WINDOW)&&(wherey()==wnds[curwnd].wndbottom-wnds[curwnd].wndtop)){
176 if (strchr(s,'\n')) {
186 if ((curwnd==LOWER_WINDOW)&&(wherey()>wnds[curwnd].wndbottom-wnds[curwnd].wndtop+1))
189 if (strchr(s,'\n') || strchr(s,'\r')) clreol();
195 void proutn(char *fmt, ...) {
200 vw_printw(stdscr, fmt, ap);
210 void prout(char *fmt, ...) {
215 vw_printw(stdscr, fmt, ap);
226 void proutc(char *line) {
227 line[strlen(line)-1] = '\0';
230 waddstr(stdscr, line);
240 static void prchr(char *s){
247 static void vprouts(char *fmt, va_list ap) {
249 vasprintf(&s, fmt, ap);
259 void prouts(char *fmt, ...) {
262 char *s, buf[BUFSIZ];
266 vsprintf(buf, fmt, ap);
269 for (s = buf; *s; s++) {
270 endTime = clock() + CLOCKS_PER_SEC*0.05;
271 while (clock() < endTime) continue;
289 void c_printf (char *format, ... )
291 char buffer[BUFSIZ]; /* Well, BUFSIZ is from ncurses... */
293 va_start(argp,format);
294 vsprintf(buffer,format,argp);
297 waddstr(conio_scr,buffer);
303 void cgetline(char *line, int max) {
306 wgetnstr(stdscr, line, max);
311 memmove(line,&line[2],max-3);
314 fgets(line, max, stdin);
315 line[strlen(line)-1] = '\0';
319 void setwnd(short wndnum){
320 /* change windows -- OK for this to be a no-op in tty mode */
323 cury=wherey()+wnds[curwnd].wndtop-wnds[wndnum].wndtop;
324 if ((curwnd==FULLSCREEN_WINDOW)&&(wndnum!=FULLSCREEN_WINDOW)) clrscr();
325 window(wnds[wndnum].wndleft, wnds[wndnum].wndtop, wnds[wndnum].wndright, wnds[wndnum].wndbottom);
326 if ((curwnd==wndnum)&&(cury>wnds[wndnum].wndbottom-wnds[wndnum].wndtop+1)){
327 gotoxy(wnds[wndnum].wndright-wnds[wndnum].wndleft+1,wnds[wndnum].wndbottom-wnds[wndnum].wndtop+1);
335 void commandhook(char *cmd, int before) {
339 * Things past this point have policy implications.
342 void drawmaps(short l) {
343 /* hook to be called after moving to redraw maps */
345 _setcursortype(_NOCURSOR);
347 if (l!=2) setwnd(LEFTUPPER_WINDOW);
352 setwnd(SRSCAN_WINDOW);
355 setwnd(LRSCAN_WINDOW);
359 _setcursortype(_NORMALCURSOR);
364 void boom(int ii, int jj)
365 /* enemy fall down, go boom */
371 setwnd(LEFTUPPER_WINDOW);
375 proutn("%c", game.quad[ii][jj]);
376 gotoxy(wherex()-1,wherey());
381 proutn("%c", game.quad[ii][jj]);
382 setwnd(LOWER_WINDOW);
384 _setcursortype(_NORMALCURSOR);
390 /* sound and visual effects for teleportation */
397 setwnd(LOWER_WINDOW);
403 prouts(" . . . . . ");
407 void tracktorpedo(int x, int y, int ix, int iy, int wait, int l, int i, int n, int iquad)
408 /* torpedo-track animation */
414 proutn("Track for torpedo number %d- ", i);
418 proutn("Torpedo track- ");
420 } else if (l==4 || l==9)
422 proutn("%d - %d ", (int)x, (int)y);
424 if (game.damage[DSRSENS]==0 || condit==IHDOCKED) {
426 delay((wait!=1)*400);
428 if ((game.quad[ix][iy]==IHDOT)||(game.quad[ix][iy]==IHBLANK)){
429 game.quad[ix][iy]='+';
431 game.quad[ix][iy]=iquad;
437 game.quad[ix][iy]|=128;
439 game.quad[ix][iy]=iquad;
440 _setcursortype(_NOCURSOR);
445 _setcursortype(_NORMALCURSOR);
448 proutn("%d - %d ", (int)x, (int)y);
453 void makechart(void) {
455 _setcursortype(_NOCURSOR);
456 setwnd(LOWER_WINDOW);
459 _setcursortype(_NORMALCURSOR);
463 void setpassword(void) {
467 strcpy(game.passwd, citem);
469 if (*game.passwd != 0) break;
470 proutn("Please type in a secret password-");
474 for(i=0;i<3;i++) game.passwd[i]=(char)(97+(int)(Rand()*25));