16 static int linecount; /* for paging */
18 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 */
36 static void outro(int sig) {
37 /* wrap up, either normally or due to signal */
47 static void fastexit(int sig) {
53 void iostart(int usecurses) {
57 setwnd(FULLSCREEN_WINDOW);
59 (void) signal(SIGINT, fastexit);
60 (void) signal(SIGINT, fastexit);
62 (void) signal(SIGIOT,fastexit); /* for assert(3) */
64 if(signal(SIGQUIT,SIG_IGN) != SIG_IGN)
65 (void)signal(SIGQUIT,fastexit);
67 if ((curses = usecurses)) {
76 scrollok(stdscr, TRUE);
77 getmaxyx(stdscr, screenheight, screenwidth);
79 char *LINES = getenv("LINES");
81 screenheight = atoi(LINES);
93 /* wait for user action -- OK to do nothing if on a TTY */
99 void pause_game(int i) {
105 setwnd(BOTTOM_WINDOW);
109 prompt = "[ANOUNCEMENT ARRIVING...]";
111 prompt = "[IMPORTANT ANNOUNCEMENT ARRIVING -- PRESS ENTER TO CONTINUE]";
115 prompt = "[CONTINUE?]";
117 prompt = "[PRESS ENTER TO CONTINUE]";
122 waddch(stdscr, '\n');
123 waddstr(stdscr, prompt);
124 wgetnstr(stdscr, buf, sizeof(buf));
130 fgets(buf, sizeof(buf), stdin);
132 /* much more in that old-TTY spirit to throw linefeeds */
134 for (j = 0; j < screenheight; j++)
143 setwnd(LOWER_WINDOW);
155 if (y == screenheight-1)
158 waddch(stdscr, '\n');
161 if (linecount >= screenheight)
167 while (i-- > 0) proutn("\n\r");
170 static void vproutn(char *fmt, va_list ap) {
172 vasprintf(&s, fmt, ap);
174 if ((curwnd==LOWER_WINDOW)&&(wherey()==wnds[curwnd].wndbottom-wnds[curwnd].wndtop)){
175 if (strchr(s,'\n')) {
185 if ((curwnd==LOWER_WINDOW)&&(wherey()>wnds[curwnd].wndbottom-wnds[curwnd].wndtop+1))
188 if (strchr(s,'\n') || strchr(s,'\r')) clreol();
194 void proutn(char *fmt, ...) {
199 vw_printw(stdscr, fmt, ap);
209 void prout(char *fmt, ...) {
214 vw_printw(stdscr, fmt, ap);
225 void proutc(char *line) {
226 line[strlen(line)-1] = '\0';
229 waddstr(stdscr, line);
239 static void prchr(char *s){
246 static void vprouts(char *fmt, va_list ap) {
248 vasprintf(&s, fmt, ap);
258 void prouts(char *fmt, ...) {
261 char *s, buf[BUFSIZ];
265 vsprintf(buf, fmt, ap);
268 for (s = buf; *s; s++) {
269 endTime = clock() + CLOCKS_PER_SEC*0.05;
270 while (clock() < endTime) continue;
288 void c_printf (char *format, ... )
290 char buffer[BUFSIZ]; /* Well, BUFSIZ is from ncurses... */
292 va_start(argp,format);
293 vsprintf(buffer,format,argp);
296 waddstr(conio_scr,buffer);
302 void cgetline(char *line, int max) {
305 wgetnstr(stdscr, line, max);
310 memmove(line,&line[2],max-3);
313 fgets(line, max, stdin);
314 line[strlen(line)-1] = '\0';
318 void setwnd(short wndnum){
319 /* change windows -- OK for this to be a no-op in tty mode */
322 cury=wherey()+wnds[curwnd].wndtop-wnds[wndnum].wndtop;
323 if ((curwnd==FULLSCREEN_WINDOW)&&(wndnum!=FULLSCREEN_WINDOW)) clrscr();
324 window(wnds[wndnum].wndleft, wnds[wndnum].wndtop, wnds[wndnum].wndright, wnds[wndnum].wndbottom);
325 if ((curwnd==wndnum)&&(cury>wnds[wndnum].wndbottom-wnds[wndnum].wndtop+1)){
326 gotoxy(wnds[wndnum].wndright-wnds[wndnum].wndleft+1,wnds[wndnum].wndbottom-wnds[wndnum].wndtop+1);
334 void commandhook(char *cmd, int before) {
338 * Things past this point have policy implications.
341 void drawmaps(short l) {
342 /* hook to be called after moving to redraw maps */
344 _setcursortype(_NOCURSOR);
346 if (l!=2) setwnd(LEFTUPPER_WINDOW);
351 setwnd(SRSCAN_WINDOW);
354 setwnd(LRSCAN_WINDOW);
358 _setcursortype(_NORMALCURSOR);
363 void boom(int ii, int jj)
364 /* enemy fall down, go boom */
370 setwnd(LEFTUPPER_WINDOW);
374 proutn("%c", game.quad[ii][jj]);
375 gotoxy(wherex()-1,wherey());
380 proutn("%c", game.quad[ii][jj]);
381 setwnd(LOWER_WINDOW);
383 _setcursortype(_NORMALCURSOR);
389 /* sound and visual effects for teleportation */
396 setwnd(LOWER_WINDOW);
402 prouts(" . . . . . ");
406 void tracktorpedo(int x, int y, int ix, int iy, int wait, int l, int i, int n, int iquad)
407 /* torpedo-track animation */
413 proutn("Track for torpedo number %d- ", i);
417 proutn("Torpedo track- ");
419 } else if (l==4 || l==9)
421 proutn("%d - %d ", (int)x, (int)y);
423 if (game.damage[DSRSENS]==0 || condit==IHDOCKED) {
425 delay((wait!=1)*400);
427 if ((game.quad[ix][iy]==IHDOT)||(game.quad[ix][iy]==IHBLANK)){
428 game.quad[ix][iy]='+';
430 game.quad[ix][iy]=iquad;
436 game.quad[ix][iy]|=128;
438 game.quad[ix][iy]=iquad;
439 _setcursortype(_NOCURSOR);
444 _setcursortype(_NORMALCURSOR);
447 proutn("%d - %d ", (int)x, (int)y);
452 void makechart(void) {
454 _setcursortype(_NOCURSOR);
455 setwnd(LOWER_WINDOW);
458 _setcursortype(_NORMALCURSOR);
462 void setpassword(void) {
466 strcpy(game.passwd, citem);
468 if (*game.passwd != 0) break;
469 proutn("Please type in a secret password-");
473 for(i=0;i<3;i++) game.passwd[i]=(char)(97+(int)(Rand()*25));