X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=blobdiff_plain;f=sst.c;h=5fc099739e6b9aaaba8fa67de1ce427f04d0606c;hp=653e06be826b8a71d4950682fa2ad04fb78f1267;hb=03ea69145938e4b01e7efc6be80a543bad1739c7;hpb=7d27c8befdb5de9a50ff4af88e764c8336bc1797 diff --git a/sst.c b/sst.c index 653e06b..5fc0997 100644 --- a/sst.c +++ b/sst.c @@ -6,11 +6,14 @@ #include #endif #include - -int getch(void); +#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); @@ -39,7 +42,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. @@ -103,7 +106,7 @@ static void listCommands(int x) { static void helpme(void) { int i, j; - char cmdbuf[32]; + char cmdbuf[32], *cp; char linebuf[132]; FILE *fp; /* Give help on commands */ @@ -130,37 +133,41 @@ static void helpme(void) { strcpy(cmdbuf, " ABBREV"); } else { - strcpy(cmdbuf, " Mnemonic: "); - j = 0; - while ((cmdbuf[j+13] = toupper(commands[i][j])) != 0) j++; + for (j = 0; commands[i][j]; j++) + cmdbuf[j] = toupper(commands[i][j]); + cmdbuf[j] = '\0'; } - fp = fopen("sst.doc", "r"); + fp = fopen(SSTDOC, "r"); if (fp == NULL) { prout("Spock- \"Captain, that information is missing from the"); prout(" computer. You need to find SST.DOC and put it in the"); prout(" current directory.\""); return; } - i = strlen(cmdbuf); - do { - if (fgets(linebuf, 132, fp) == NULL) { + for (;;) { + if (fgets(linebuf, sizeof(linebuf), fp) == NULL) { prout("Spock- \"Captain, there is no information on that command.\""); fclose(fp); return; } - } while (strncmp(linebuf, cmdbuf, i) != 0); + if (linebuf[0] == '%' && linebuf[1] == '%'&& linebuf[2] == ' ') { + for (cp = linebuf+3; isspace(*cp); cp++) + continue; + linebuf[strlen(linebuf)-1] = '\0'; + if (strcmp(cp, cmdbuf) == 0) + break; + } + } skip(1); prout("Spock- \"Captain, I've found the following information:\""); skip(1); - do { - if (linebuf[0]!=12) { // ignore page break lines - linebuf[strlen(linebuf)-1] = '\0'; // No \n at end - prout(linebuf); - } - fgets(linebuf,132,fp); - } while (strstr(linebuf, "******")==NULL); + while (fgets(linebuf, sizeof(linebuf),fp)) { + if (strstr(linebuf, "******")) + break; + proutc(linebuf); + } fclose(fp); } @@ -350,20 +357,21 @@ int main(int argc, char **argv) { int hitme; char ch; prelim(); + char *LINES = getenv("LINES"); + + if (LINES) + screenheight = atoi(LINES); + line[0] = '\0'; if (argc > 1) { - fromcommandline = 1; - line[0] = '\0'; while (--argc > 0) { strcat(line, *(++argv)); strcat(line, " "); } } - else fromcommandline = 0; - while (TRUE) { /* Play a game */ - setup(); + setup(line[0] == '\0'); if (alldone) { score(); alldone = 0; @@ -539,29 +547,33 @@ static void clearscreen(void) { extern void clrscr(void); clrscr(); #else - proutn("\033[2J"); /* Hope for an ANSI display */ + // 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 -- HIT SPACE BAR TO CONTINUE]"); - getch(); + prout("[IMPORTANT ANNOUNCEMENT ARRIVING -- PRESS ENTER TO CONTINUE]"); } else { - if (skill > 2) - proutn("[CONTINUE?]"); - else - proutn("[HIT SPACE BAR TO CONTINUE]"); - getch(); - proutn("\r \r"); + if (skill > 2) + proutn("[CONTINUE?]"); + else + proutn("[PRESS ENTER TO CONTINUE]"); + } + fgets(buf, sizeof(buf), stdin); if (i != 0) { clearscreen(); } @@ -572,7 +584,7 @@ void pause(int i) { void skip(int i) { while (i-- > 0) { linecount++; - if (linecount >= 23) + if (linecount >= screenheight) pause(0); else putchar('\n'); @@ -595,6 +607,12 @@ void prout(char *fmt, ...) { 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]; @@ -677,7 +695,7 @@ void debugme(void) { case FSCMOVE: proutn("SC Move "); break; case FSCDBAS: proutn("SC Base Destroy "); break; } - proutn("%82.2f", future[i]-game.state.date); + proutn("%.2f", future[i]-game.state.date); chew(); proutn(" ?"); key = scan();