16 static int linecount; /* for paging */
17 static int screenheight = 24, screenwidth = 80;
20 static int curses = FALSE;
22 static int curses = TRUE;
27 int wndleft,wndtop,wndright,wndbottom;
29 static wnd wnds[6]={{1,1,80,25}, /* FULLSCREEN_WINDOW */
30 {1,1,25,12}, /* LEFTUPPER_WINDOW */
31 {26,2,80,12}, /* SRSCAN_WINDOW */
32 {65,1,80,10}, /* LRSCAN_WINDOW */
33 {1,13,80,23}, /* LOWER_WINDOW */
34 {1,24,80,25}, /* BOTTOM_WINDOW */
40 static void outro(int sig) {
41 /* wrap up, either normally or due to signal */
51 static void fastexit(int sig) {
58 void iostart(int usecurses) {
63 setwnd(FULLSCREEN_WINDOW);
65 (void) signal(SIGINT, fastexit);
66 (void) signal(SIGINT, fastexit);
68 (void) signal(SIGIOT,fastexit); /* for assert(3) */
70 if(signal(SIGQUIT,SIG_IGN) != SIG_IGN)
71 (void)signal(SIGQUIT,fastexit);
73 if ((curses = usecurses)) {
82 scrollok(stdscr, TRUE);
83 getmaxyx(stdscr, screenheight, screenwidth);
85 char *LINES = getenv("LINES");
87 screenheight = atoi(LINES);
99 /* wait for user action -- OK to do nothing if on a TTY */
105 void pause_game(int i) {
111 setwnd(BOTTOM_WINDOW);
115 prompt = "[ANOUNCEMENT ARRIVING...]";
117 prompt = "[IMPORTANT ANNOUNCEMENT ARRIVING -- PRESS ENTER TO CONTINUE]";
121 prompt = "[CONTINUE?]";
123 prompt = "[PRESS ENTER TO CONTINUE]";
128 waddch(stdscr, '\n');
129 waddstr(stdscr, prompt);
130 wgetnstr(stdscr, buf, sizeof(buf));
136 fgets(buf, sizeof(buf), stdin);
138 /* much more in that old-TTY spirit to throw linefeeds */
140 for (j = 0; j < screenheight; j++)
149 setwnd(LOWER_WINDOW);
161 if (y == screenheight-1)
164 waddch(stdscr, '\n');
167 if (linecount >= screenheight)
173 while (i-- > 0) proutn("\n\r");
177 static void vproutn(char *fmt, va_list ap) {
180 vasprintf(&s, fmt, ap);
182 if ((curwnd==LOWER_WINDOW)&&(wherey()==wnds[curwnd].wndbottom-wnds[curwnd].wndtop)){
183 if (strchr(s,'\n')) {
193 if ((curwnd==LOWER_WINDOW)&&(wherey()>wnds[curwnd].wndbottom-wnds[curwnd].wndtop+1))
196 if (strchr(s,'\n') || strchr(s,'\r')) clreol();
202 void proutn(char *fmt, ...) {
207 vw_printw(stdscr, fmt, ap);
217 void prout(char *fmt, ...) {
222 vw_printw(stdscr, fmt, ap);
233 void proutc(char *line) {
234 line[strlen(line)-1] = '\0';
237 waddstr(stdscr, line);
247 static void prchr(char *s){
254 static void vprouts(char *fmt, va_list ap) {
256 vasprintf(&s, fmt, ap);
266 void prouts(char *fmt, ...) {
269 char *s, buf[BUFSIZ];
273 vsprintf(buf, fmt, ap);
276 for (s = buf; *s; s++) {
277 endTime = clock() + CLOCKS_PER_SEC*0.05;
278 while (clock() < endTime) continue;
296 void cgetline(char *line, int max) {
299 wgetnstr(stdscr, line, max);
304 memmove(line,&line[2],max-3);
307 fgets(line, max, stdin);
308 line[strlen(line)-1] = '\0';
312 void setwnd(short wndnum){
313 /* change windows -- OK for this to be a no-op in tty mode */
316 cury=wherey()+wnds[curwnd].wndtop-wnds[wndnum].wndtop;
317 if ((curwnd==FULLSCREEN_WINDOW)&&(wndnum!=FULLSCREEN_WINDOW)) clrscr();
318 window(wnds[wndnum].wndleft, wnds[wndnum].wndtop, wnds[wndnum].wndright, wnds[wndnum].wndbottom);
319 if ((curwnd==wndnum)&&(cury>wnds[wndnum].wndbottom-wnds[wndnum].wndtop+1)){
320 gotoxy(wnds[wndnum].wndright-wnds[wndnum].wndleft+1,wnds[wndnum].wndbottom-wnds[wndnum].wndtop+1);
328 void commandhook(char *cmd, int before) {
332 * Things past this point have policy implications.
335 void drawmaps(short l) {
336 /* hook to be called after moving to redraw maps */
338 _setcursortype(_NOCURSOR);
340 if (l!=2) setwnd(LEFTUPPER_WINDOW);
345 setwnd(SRSCAN_WINDOW);
347 srscan(SCAN_NO_LEFTSIDE);
348 setwnd(LRSCAN_WINDOW);
352 _setcursortype(_NORMALCURSOR);
357 void boom(int ii, int jj)
358 /* enemy fall down, go boom */
364 setwnd(LEFTUPPER_WINDOW);
368 proutn("%c", game.quad[ii][jj]);
369 gotoxy(wherex()-1,wherey());
374 proutn("%c", game.quad[ii][jj]);
375 setwnd(LOWER_WINDOW);
377 _setcursortype(_NORMALCURSOR);
383 /* sound and visual effects for teleportation */
390 setwnd(LOWER_WINDOW);
396 prouts(" . . . . . ");
400 void tracktorpedo(int x, int y, int ix, int iy, int wait, int l, int i, int n, int iquad)
401 /* torpedo-track animation */
407 proutn("Track for torpedo number %d- ", i);
411 proutn("Torpedo track- ");
413 } else if (l==4 || l==9)
415 proutn("%d - %d ", (int)x, (int)y);
417 if (game.damage[DSRSENS]==0 || condit==IHDOCKED) {
422 delay((wait!=1)*400);
424 if ((game.quad[ix][iy]==IHDOT)||(game.quad[ix][iy]==IHBLANK)){
425 game.quad[ix][iy]='+';
427 game.quad[ix][iy]=iquad;
433 game.quad[ix][iy]|=128;
435 game.quad[ix][iy]=iquad;
436 _setcursortype(_NOCURSOR);
441 _setcursortype(_NORMALCURSOR);
445 proutn("%d - %d ", (int)x, (int)y);
450 void makechart(void) {
452 _setcursortype(_NOCURSOR);
453 setwnd(LOWER_WINDOW);
456 _setcursortype(_NORMALCURSOR);
460 void setpassword(void) {
464 strcpy(game.passwd, citem);
466 if (*game.passwd != 0) break;
467 proutn("Please type in a secret password-");
471 for(i=0;i<3;i++) game.passwd[i]=(char)(97+(int)(Rand()*25));