X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=sst.c;h=d35b2556ae1407f297b0088838a2c5124b1140c0;hb=25f221b092e0e9d85aa5d3e6863043f2ab4d7c43;hp=b3a0202663bd5d6760366c82f8a1bf73d4f24545;hpb=dd95aad0a184fc4f2ab4cd13323a70c9833acc2b;p=super-star-trek.git diff --git a/sst.c b/sst.c index b3a0202..d35b255 100644 --- a/sst.c +++ b/sst.c @@ -1,19 +1,12 @@ #define INCLUDED // Define externs here #include "sst.h" #include -#include -#ifdef MSDOS -#include + +#ifndef SSTDOC +#define SSTDOC "sst.doc" #endif -#include -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 @@ -40,7 +33,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. @@ -135,7 +128,7 @@ static void helpme(void) { 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"); @@ -164,8 +157,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); } @@ -355,25 +347,19 @@ int main(int argc, char **argv) { int i; int hitme; char ch; - prelim(); - char *LINES = getenv("LINES"); - - if (LINES) - screenheight = atoi(LINES); + prelim(); + iostart(); + 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; @@ -430,7 +416,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)); } @@ -468,14 +454,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; } @@ -484,8 +468,6 @@ int scan(void) { int i; char *cp; - linecount = 0; - // Init result aaitem = 0.0; *citem = 0; @@ -543,85 +525,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);