X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=sst.c;h=888b7ec4780b01333e7a04905a7dbef65e07d6c5;hb=cf91699c89b88f76dcf63c60624635184e8cb7eb;hp=ae209e2cb373ed7cf7ad8a156e1fbf01b55bc092;hpb=d1e79ed7b6329d2c7e26a99402d90b0041fc593f;p=super-star-trek.git diff --git a/sst.c b/sst.c index ae209e2..888b7ec 100644 --- a/sst.c +++ b/sst.c @@ -1,23 +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 -int getch(void); - 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 @@ -44,7 +34,7 @@ static void clearscreen(void); 2. deathray improvement (but keeping original failure alternatives) 3. Tholian Web - +s 4. Enemies can ram the Enterprise. Regular Klingons and Romulans can move in Expert and Emeritus games. This code could use improvement. @@ -168,8 +158,7 @@ static void helpme(void) { while (fgets(linebuf, sizeof(linebuf),fp)) { if (strstr(linebuf, "******")) break; - /* use fputs here to avoid % expansion */ - fputs(linebuf, stdout); + proutc(linebuf); } fclose(fp); } @@ -201,6 +190,7 @@ static void makemoves(void) { } else prout("UNRECOGNIZED COMMAND."); } + commandhook(commands[i], TRUE); switch (i) { /* command switch */ case 0: // srscan srscan(1); @@ -227,7 +217,8 @@ static void makemoves(void) { } break; case 6: // dock - dock(); + dock(1); + if (ididit) attack(0); break; case 7: // damages dreprt(); @@ -325,6 +316,7 @@ static void makemoves(void) { helpme(); // get help break; } + commandhook(commands[i], FALSE); for (;;) { if (alldone) break; // Game has ended #ifdef DEBUG @@ -356,28 +348,30 @@ 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); - - if (argc > 1) { - fromcommandline = 1; - line[0] = '\0'; - while (--argc > 0) { - strcat(line, *(++argv)); - strcat(line, " "); - } - } - else fromcommandline = 0; + 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(); + setup(line[0] == '\0'); if (alldone) { score(); alldone = 0; @@ -398,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."); } @@ -417,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); @@ -434,7 +430,7 @@ char *cramlc(enum loctype key, int x, int y) { void crmena(int i, int enemy, int key, int x, int y) { if (i == 1) proutn("***"); cramen(enemy); - proutn(" at"); + proutn(" at "); proutn(cramlc(key, x, y)); } @@ -472,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; } @@ -488,8 +482,6 @@ int scan(void) { int i; char *cp; - linecount = 0; - // Init result aaitem = 0.0; *citem = 0; @@ -500,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 @@ -513,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; @@ -545,87 +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 */ -#endif -} - -/* We will pull these out in case we want to do something special later */ - -void pause(int i) { - putchar('\n'); - if (i==1) { - if (skill > 2) - prout("[ANOUNCEMENT ARRIVING...]"); - else - prout("[IMPORTANT ANNOUNCEMENT ARRIVING -- HIT SPACE BAR TO CONTINUE]"); - getch(); - } - else { - if (skill > 2) - proutn("[CONTINUE?]"); - else - proutn("[HIT SPACE BAR TO CONTINUE]"); - getch(); - proutn("\r \r"); - } - 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 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);