Rewrote the command dispatcher.
[super-star-trek.git] / io.c
diff --git a/io.c b/io.c
index 2e66d36f10ec197929d3fbcdd47fd3478de4aacf..4ca069ff8f7844a16648b5b6fb07bc7e3521923a 100644 (file)
--- a/io.c
+++ b/io.c
@@ -81,30 +81,18 @@ void ioend(void) {
     outro(0);
 }
 
-void clearscreen(void) {
-       /* Somehow we need to clear the screen */
-#ifdef __BORLANDC__
-       extern void clrscr(void);
-       clrscr();
-#else
-       if (curses) {
-           wclear(stdscr);
-           wrefresh(stdscr);
-       } else {
-               // proutn("\033[2J"); /* Hope for an ANSI display */
-               /* much more in that old-TTY spirit to just throw linefeeds */
-               int i;
-               for (i = 0; i < screenheight; i++)
-                   putchar('\n');
-       }
-#endif
+void waitfor(void) {
+/* wait for user action -- OK to do nothing if on a TTY */
+#ifdef SERGEEV
+       getche();
+#endif /* SERGEEV */
 }
 
 void pause_game(int i) {
+       char *prompt;
 #ifndef SERGEEV
-    char buf[BUFSIZ], *prompt;
+        char buf[BUFSIZ];
 #else /* SERGEEV */
-       char *prompt;
         drawmaps(0);
         setwnd(5);
 #endif /* SERGEEV */
@@ -133,7 +121,10 @@ void pause_game(int i) {
                proutn(prompt);
                fgets(buf, sizeof(buf), stdin);
                if (i != 0) {
-                       clearscreen();
+                   /* much more in that old-TTY spirit to throw linefeeds */
+                   int j;
+                   for (j = 0; j < screenheight; j++)
+                       putchar('\n');
                }
                linecount = 0;
        }
@@ -286,6 +277,54 @@ void prouts(char *fmt, ...) {
 #endif /* SERGEEV */
 }
 
+void c_printf (char *format, ... )
+{
+    char buffer[BUFSIZ]; /* Well, BUFSIZ is from ncurses...  */
+    va_list argp;
+    va_start(argp,format);
+    vsprintf(buffer,format,argp);
+    va_end(argp);
+#ifdef SERGEEV
+    waddstr(conio_scr,buffer);
+#else
+    proutn(buffer);
+#endif /* SERGEEV */
+}
+
+void warble(void)
+/* sound and visual effects for teleportation */
+{
+#ifdef SERGEEV
+    int posx, posy;
+    posx=wherex();
+    posy=wherey();
+    drawmaps(1);
+    setwnd(4);
+    gotoxy(posx,posy);
+    sound(50);
+    delay(1000);
+    nosound();
+#else
+    prouts(" . . . . . ");
+#endif /* SERGEEV */
+}
+
+void setpassword(void) {
+#ifndef SERGEEV
+       while (TRUE) {
+               scan();
+               strcpy(game.passwd, citem);
+               chew();
+               if (*game.passwd != 0) break;
+               proutn("Please type in a secret password-");
+       }
+#else
+       int i;
+        for(i=0;i<3;i++) game.passwd[i]=(char)(97+(int)(Rand()*25));
+        game.passwd[3]=0;
+#endif /* SERGEEV */
+}
+
 void getline(char *line, int max) {
     if (curses) {
 #ifndef SERGEEV
@@ -302,5 +341,21 @@ void getline(char *line, int max) {
     }
 }
 
+void setwnd(short wndnum){
+/* change windows -- OK for this to be a no-op in tty mode */
+#ifdef SERGEEV
+     int cury;
+     cury=wherey()+wnds[curwnd].wndtop-wnds[wndnum].wndtop;
+     if ((curwnd==0)&&(wndnum!=0)) clrscr();
+     window(wnds[wndnum].wndleft, wnds[wndnum].wndtop, wnds[wndnum].wndright, wnds[wndnum].wndbottom);
+     if ((curwnd==wndnum)&&(cury>wnds[wndnum].wndbottom-wnds[wndnum].wndtop+1)){
+        gotoxy(wnds[wndnum].wndright-wnds[wndnum].wndleft+1,wnds[wndnum].wndbottom-wnds[wndnum].wndtop+1);
+       skip(1);
+     }
+     curwnd=wndnum;
+     gotoxy(1,cury);
+#endif /* SERGEEV */
+}
+
 void commandhook(char *cmd, int before) {
 }