16 static int linecount; /* for paging */
17 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 */
37 static void outro(int sig) {
38 /* wrap up, either normally or due to signal */
48 static void fastexit(int sig) {
55 void iostart(int usecurses) {
60 setwnd(FULLSCREEN_WINDOW);
62 (void) signal(SIGINT, fastexit);
63 (void) signal(SIGINT, fastexit);
65 (void) signal(SIGIOT,fastexit); /* for assert(3) */
67 if(signal(SIGQUIT,SIG_IGN) != SIG_IGN)
68 (void)signal(SIGQUIT,fastexit);
70 if ((curses = usecurses)) {
79 scrollok(stdscr, TRUE);
80 getmaxyx(stdscr, screenheight, screenwidth);
82 char *LINES = getenv("LINES");
84 screenheight = atoi(LINES);
96 /* wait for user action -- OK to do nothing if on a TTY */
102 void pause_game(int i) {
108 setwnd(BOTTOM_WINDOW);
112 prompt = "[ANOUNCEMENT ARRIVING...]";
114 prompt = "[IMPORTANT ANNOUNCEMENT ARRIVING -- PRESS ENTER TO CONTINUE]";
118 prompt = "[CONTINUE?]";
120 prompt = "[PRESS ENTER TO CONTINUE]";
125 waddch(stdscr, '\n');
126 waddstr(stdscr, prompt);
127 wgetnstr(stdscr, buf, sizeof(buf));
133 fgets(buf, sizeof(buf), stdin);
135 /* much more in that old-TTY spirit to throw linefeeds */
137 for (j = 0; j < screenheight; j++)
146 setwnd(LOWER_WINDOW);
158 if (y == screenheight-1)
161 waddch(stdscr, '\n');
164 if (linecount >= screenheight)
170 while (i-- > 0) proutn("\n\r");
174 static void vproutn(char *fmt, va_list ap) {
177 vasprintf(&s, fmt, ap);
179 if ((curwnd==LOWER_WINDOW)&&(wherey()==wnds[curwnd].wndbottom-wnds[curwnd].wndtop)){
180 if (strchr(s,'\n')) {
190 if ((curwnd==LOWER_WINDOW)&&(wherey()>wnds[curwnd].wndbottom-wnds[curwnd].wndtop+1))
193 if (strchr(s,'\n') || strchr(s,'\r')) clreol();
199 void proutn(char *fmt, ...) {
204 vw_printw(stdscr, fmt, ap);
214 void prout(char *fmt, ...) {
219 vw_printw(stdscr, fmt, ap);
230 void proutc(char *line) {
231 line[strlen(line)-1] = '\0';
234 waddstr(stdscr, line);
244 static void prchr(char *s){
251 static void vprouts(char *fmt, va_list ap) {
253 vasprintf(&s, fmt, ap);
263 void prouts(char *fmt, ...) {
266 char *s, buf[BUFSIZ];
270 vsprintf(buf, fmt, ap);
273 for (s = buf; *s; s++) {
274 endTime = clock() + CLOCKS_PER_SEC*0.05;
275 while (clock() < endTime) continue;
293 void cgetline(char *line, int max) {
296 wgetnstr(stdscr, line, max);
301 memmove(line,&line[2],max-3);
304 fgets(line, max, stdin);
305 line[strlen(line)-1] = '\0';
309 void setwnd(short wndnum){
310 /* change windows -- OK for this to be a no-op in tty mode */
313 cury=wherey()+wnds[curwnd].wndtop-wnds[wndnum].wndtop;
314 if ((curwnd==FULLSCREEN_WINDOW)&&(wndnum!=FULLSCREEN_WINDOW)) clrscr();
315 window(wnds[wndnum].wndleft, wnds[wndnum].wndtop, wnds[wndnum].wndright, wnds[wndnum].wndbottom);
316 if ((curwnd==wndnum)&&(cury>wnds[wndnum].wndbottom-wnds[wndnum].wndtop+1)){
317 gotoxy(wnds[wndnum].wndright-wnds[wndnum].wndleft+1,wnds[wndnum].wndbottom-wnds[wndnum].wndtop+1);
325 void commandhook(char *cmd, int before) {
329 * Things past this point have policy implications.
332 void drawmaps(short l) {
333 /* hook to be called after moving to redraw maps */
335 _setcursortype(_NOCURSOR);
337 if (l!=2) setwnd(LEFTUPPER_WINDOW);
342 setwnd(SRSCAN_WINDOW);
344 srscan(SCAN_NO_LEFTSIDE);
345 setwnd(LRSCAN_WINDOW);
349 _setcursortype(_NORMALCURSOR);
354 void boom(int ii, int jj)
355 /* enemy fall down, go boom */
361 setwnd(LEFTUPPER_WINDOW);
365 proutn("%c", game.quad[ii][jj]);
366 gotoxy(wherex()-1,wherey());
371 proutn("%c", game.quad[ii][jj]);
372 setwnd(LOWER_WINDOW);
374 _setcursortype(_NORMALCURSOR);
380 /* sound and visual effects for teleportation */
387 setwnd(LOWER_WINDOW);
393 prouts(" . . . . . ");
397 void tracktorpedo(int x, int y, int ix, int iy, int wait, int l, int i, int n, int iquad)
398 /* torpedo-track animation */
404 proutn("Track for torpedo number %d- ", i);
408 proutn("Torpedo track- ");
410 } else if (l==4 || l==9)
412 proutn("%d - %d ", (int)x, (int)y);
414 if (game.damage[DSRSENS]==0 || condit==IHDOCKED) {
416 delay((wait!=1)*400);
418 if ((game.quad[ix][iy]==IHDOT)||(game.quad[ix][iy]==IHBLANK)){
419 game.quad[ix][iy]='+';
421 game.quad[ix][iy]=iquad;
427 game.quad[ix][iy]|=128;
429 game.quad[ix][iy]=iquad;
430 _setcursortype(_NOCURSOR);
435 _setcursortype(_NORMALCURSOR);
438 proutn("%d - %d ", (int)x, (int)y);
443 void makechart(void) {
445 _setcursortype(_NOCURSOR);
446 setwnd(LOWER_WINDOW);
449 _setcursortype(_NORMALCURSOR);
453 void setpassword(void) {
457 strcpy(game.passwd, citem);
459 if (*game.passwd != 0) break;
460 proutn("Please type in a secret password-");
464 for(i=0;i<3;i++) game.passwd[i]=(char)(97+(int)(Rand()*25));