15 static int linecount; /* for paging */
16 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 */
36 static void outro(int sig) {
37 /* wrap up, either normally or due to signal */
47 static void fastexit(int sig) {
54 void iostart(int usecurses) {
58 setwnd(FULLSCREEN_WINDOW);
60 (void) signal(SIGINT, fastexit);
61 (void) signal(SIGINT, fastexit);
63 (void) signal(SIGIOT,fastexit); /* for assert(3) */
65 if(signal(SIGQUIT,SIG_IGN) != SIG_IGN)
66 (void)signal(SIGQUIT,fastexit);
68 if ((curses = usecurses)) {
77 scrollok(stdscr, TRUE);
78 getmaxyx(stdscr, screenheight, screenwidth);
80 char *LINES = getenv("LINES");
82 screenheight = atoi(LINES);
94 /* wait for user action -- OK to do nothing if on a TTY */
100 void pause_game(int i) {
106 setwnd(BOTTOM_WINDOW);
110 prompt = "[ANOUNCEMENT ARRIVING...]";
112 prompt = "[IMPORTANT ANNOUNCEMENT ARRIVING -- PRESS ENTER TO CONTINUE]";
116 prompt = "[CONTINUE?]";
118 prompt = "[PRESS ENTER TO CONTINUE]";
123 waddch(stdscr, '\n');
124 waddstr(stdscr, prompt);
125 wgetnstr(stdscr, buf, sizeof(buf));
131 fgets(buf, sizeof(buf), stdin);
133 /* much more in that old-TTY spirit to throw linefeeds */
135 for (j = 0; j < screenheight; j++)
144 setwnd(LOWER_WINDOW);
156 if (y == screenheight-1)
159 waddch(stdscr, '\n');
162 if (linecount >= screenheight)
168 while (i-- > 0) proutn("\n\r");
172 static void vproutn(char *fmt, va_list ap) {
175 vasprintf(&s, fmt, ap);
177 if ((curwnd==LOWER_WINDOW)&&(wherey()==wnds[curwnd].wndbottom-wnds[curwnd].wndtop)){
178 if (strchr(s,'\n')) {
188 if ((curwnd==LOWER_WINDOW)&&(wherey()>wnds[curwnd].wndbottom-wnds[curwnd].wndtop+1))
191 if (strchr(s,'\n') || strchr(s,'\r')) clreol();
197 void proutn(char *fmt, ...) {
202 vw_printw(stdscr, fmt, ap);
212 void prout(char *fmt, ...) {
217 vw_printw(stdscr, fmt, ap);
228 void proutc(char *line) {
229 line[strlen(line)-1] = '\0';
232 waddstr(stdscr, line);
242 static void prchr(char *s){
249 static void vprouts(char *fmt, va_list ap) {
251 vasprintf(&s, fmt, ap);
261 void prouts(char *fmt, ...) {
264 char *s, buf[BUFSIZ];
268 vsprintf(buf, fmt, ap);
271 for (s = buf; *s; s++) {
272 endTime = clock() + CLOCKS_PER_SEC*0.05;
273 while (clock() < endTime) continue;
291 void c_printf (char *format, ... )
293 char buffer[BUFSIZ]; /* Well, BUFSIZ is from ncurses... */
295 va_start(argp,format);
296 vsprintf(buffer,format,argp);
299 waddstr(conio_scr,buffer);
305 void cgetline(char *line, int max) {
308 wgetnstr(stdscr, line, max);
313 memmove(line,&line[2],max-3);
316 fgets(line, max, stdin);
317 line[strlen(line)-1] = '\0';
321 void setwnd(short wndnum){
322 /* change windows -- OK for this to be a no-op in tty mode */
325 cury=wherey()+wnds[curwnd].wndtop-wnds[wndnum].wndtop;
326 if ((curwnd==FULLSCREEN_WINDOW)&&(wndnum!=FULLSCREEN_WINDOW)) clrscr();
327 window(wnds[wndnum].wndleft, wnds[wndnum].wndtop, wnds[wndnum].wndright, wnds[wndnum].wndbottom);
328 if ((curwnd==wndnum)&&(cury>wnds[wndnum].wndbottom-wnds[wndnum].wndtop+1)){
329 gotoxy(wnds[wndnum].wndright-wnds[wndnum].wndleft+1,wnds[wndnum].wndbottom-wnds[wndnum].wndtop+1);
337 void commandhook(char *cmd, int before) {
341 * Things past this point have policy implications.
344 void drawmaps(short l) {
345 /* hook to be called after moving to redraw maps */
347 _setcursortype(_NOCURSOR);
349 if (l!=2) setwnd(LEFTUPPER_WINDOW);
354 setwnd(SRSCAN_WINDOW);
356 srscan(SCAN_NO_LEFTSIDE);
357 setwnd(LRSCAN_WINDOW);
361 _setcursortype(_NORMALCURSOR);
366 void boom(int ii, int jj)
367 /* enemy fall down, go boom */
373 setwnd(LEFTUPPER_WINDOW);
377 proutn("%c", game.quad[ii][jj]);
378 gotoxy(wherex()-1,wherey());
383 proutn("%c", game.quad[ii][jj]);
384 setwnd(LOWER_WINDOW);
386 _setcursortype(_NORMALCURSOR);
392 /* sound and visual effects for teleportation */
399 setwnd(LOWER_WINDOW);
405 prouts(" . . . . . ");
409 void tracktorpedo(int x, int y, int ix, int iy, int wait, int l, int i, int n, int iquad)
410 /* torpedo-track animation */
416 proutn("Track for torpedo number %d- ", i);
420 proutn("Torpedo track- ");
422 } else if (l==4 || l==9)
424 proutn("%d - %d ", (int)x, (int)y);
426 if (game.damage[DSRSENS]==0 || condit==IHDOCKED) {
428 delay((wait!=1)*400);
430 if ((game.quad[ix][iy]==IHDOT)||(game.quad[ix][iy]==IHBLANK)){
431 game.quad[ix][iy]='+';
433 game.quad[ix][iy]=iquad;
439 game.quad[ix][iy]|=128;
441 game.quad[ix][iy]=iquad;
442 _setcursortype(_NOCURSOR);
447 _setcursortype(_NORMALCURSOR);
450 proutn("%d - %d ", (int)x, (int)y);
455 void makechart(void) {
457 _setcursortype(_NOCURSOR);
458 setwnd(LOWER_WINDOW);
461 _setcursortype(_NORMALCURSOR);
465 void setpassword(void) {
469 strcpy(game.passwd, citem);
471 if (*game.passwd != 0) break;
472 proutn("Please type in a secret password-");
476 for(i=0;i<3;i++) game.passwd[i]=(char)(97+(int)(Rand()*25));