X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=sst.c;h=888b7ec4780b01333e7a04905a7dbef65e07d6c5;hb=cf91699c89b88f76dcf63c60624635184e8cb7eb;hp=ee5bd3eeb3c64ca443c67fc1696a015ec752df79;hpb=5ac8c94a3ddf49203587787f3cb0d85052e51d55;p=super-star-trek.git diff --git a/sst.c b/sst.c index ee5bd3e..888b7ec 100644 --- a/sst.c +++ b/sst.c @@ -1,21 +1,13 @@ #define INCLUDED // Define externs here -#include "sst.h" #include -#include -#ifdef MSDOS -#include -#endif -#include +#include +#include "sst.h" #ifndef SSTDOC #define SSTDOC "sst.doc" #endif static char line[128], *linep = line; -static int linecount; /* for paging */ -static int screenheight = 24; - -static void clearscreen(void); /* Compared to original version, I've changed the "help" command to "call" and the "terminate" command to "quit" to better match @@ -198,6 +190,7 @@ static void makemoves(void) { } else prout("UNRECOGNIZED COMMAND."); } + commandhook(commands[i], TRUE); switch (i) { /* command switch */ case 0: // srscan srscan(1); @@ -224,7 +217,8 @@ static void makemoves(void) { } break; case 6: // dock - dock(); + dock(1); + if (ididit) attack(0); break; case 7: // damages dreprt(); @@ -322,6 +316,7 @@ static void makemoves(void) { helpme(); // get help break; } + commandhook(commands[i], FALSE); for (;;) { if (alldone) break; // Game has ended #ifdef DEBUG @@ -353,23 +348,28 @@ static void makemoves(void) { int main(int argc, char **argv) { - int i; + int i, option, usecurses = TRUE; int hitme; char ch; - prelim(); - char *LINES = getenv("LINES"); - - if (LINES) - screenheight = atoi(LINES); - line[0] = '\0'; - if (argc > 1) { - while (--argc > 0) { - strcat(line, *(++argv)); - strcat(line, " "); - } + while ((option = getopt(argc, argv, "t")) != -1) { + switch (option) { + case 't': + usecurses = FALSE; + break; + default: + fprintf(stderr, "usage: sst [-t] [startcommand...].\n"); + exit(0); + } } + iostart(usecurses); + prelim(); + line[0] = '\0'; + for (i = optind; i < argc; i++) { + strcat(line, argv[i]); + strcat(line, " "); + } while (TRUE) { /* Play a game */ setup(line[0] == '\0'); if (alldone) { @@ -392,7 +392,8 @@ int main(int argc, char **argv) { if (!ja()) break; } skip(1); - prout("May the Great Bird of the Galaxy roost upon your home planet."); + ioend(); + puts("May the Great Bird of the Galaxy roost upon your home planet."); } @@ -411,6 +412,7 @@ void cramen(int i) { case IHBLANK: s = "Black hole"; break; case IHT: s = "Tholian"; break; case IHWEB: s = "Tholian web"; break; + case IHQUEST: s = "Stranger"; break; default: s = "Unknown??"; break; } proutn(s); @@ -466,14 +468,12 @@ void iran10(int *i, int *j) { } void chew(void) { - linecount = 0; linep = line; *linep = 0; } void chew2(void) { /* return IHEOL next time */ - linecount = 0; linep = line+1; *linep = 0; } @@ -482,8 +482,6 @@ int scan(void) { int i; char *cp; - linecount = 0; - // Init result aaitem = 0.0; *citem = 0; @@ -494,8 +492,7 @@ int scan(void) { chew(); return IHEOL; } - fgets(line, sizeof(line), stdin); - line[strlen(line)-1] = '\0'; + getline(line, sizeof(line)); linep = line; } // Skip leading white space @@ -507,6 +504,7 @@ int scan(void) { } if (isdigit(*linep) || *linep=='+' || *linep=='-' || *linep=='.') { // treat as a number + i = 0; if (sscanf(linep, "%lf%n", &aaitem, &i) < 1) { linep = line; // Invalid numbers are ignored *linep = 0; @@ -539,97 +537,6 @@ int ja(void) { } } -double square(double i) { return i*i; } - -static void clearscreen(void) { - /* Somehow we need to clear the screen */ -#ifdef __BORLANDC__ - extern void clrscr(void); - clrscr(); -#else - // proutn("\033[2J"); /* Hope for an ANSI display */ - /* much more in that old-time TTY spirit to just throw linefeeds */ - int i; - for (i = 0; i < screenheight; i++) - putchar('\n'); -#endif -} - -/* We will pull these out in case we want to do something special later */ - -void pause(int i) { - char buf[BUFSIZ]; - putchar('\n'); - if (i==1) { - if (skill > 2) - prout("[ANOUNCEMENT ARRIVING...]"); - else - prout("[IMPORTANT ANNOUNCEMENT ARRIVING -- PRESS ENTER TO CONTINUE]"); - } - else { - if (skill > 2) - proutn("[CONTINUE?]"); - else - proutn("[PRESS ENTER TO CONTINUE]"); - - } - fgets(buf, sizeof(buf), stdin); - if (i != 0) { - clearscreen(); - } - linecount = 0; -} - - -void skip(int i) { - while (i-- > 0) { - linecount++; - if (linecount >= screenheight) - pause(0); - else - putchar('\n'); - } -} - - -void proutn(char *fmt, ...) { - va_list ap; - va_start(ap, fmt); - vprintf(fmt, ap); - va_end(ap); -} - -void prout(char *fmt, ...) { - va_list ap; - va_start(ap, fmt); - vprintf(fmt, ap); - va_end(ap); - skip(1); -} - -void proutc(char *line) { - line[strlen(line)-1] = '\0'; - fputs(line, stdout); - skip(1); -} - -void prouts(char *fmt, ...) { - clock_t endTime; - char *s, buf[BUFSIZ]; - /* print slowly! */ - va_list ap; - va_start(ap, fmt); - vsprintf(buf, fmt, ap); - va_end(ap); - skip(1); - for (s = buf; *s; s++) { - endTime = clock() + CLOCKS_PER_SEC*0.05; - while (clock() < endTime) ; - putchar(*s); - fflush(stdout); - } -} - void huh(void) { chew(); skip(1);