X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=blobdiff_plain;f=sst.c;h=b06a82fade956d28bd2b9b4f6b32a250d39db369;hp=e4fe2afe0fcf55a0eab1f3f5d3a4001e47c6bd79;hb=d5826a672dd4afc591476655b4905cb6542cd89c;hpb=f14a35629e403d9b2cd4e406e80666671fd2a594 diff --git a/sst.c b/sst.c index e4fe2af..b06a82f 100644 --- a/sst.c +++ b/sst.c @@ -1,6 +1,7 @@ #define INCLUDED // Define externs here #include "sst.h" #include +#include #ifdef MSDOS #include #endif @@ -102,7 +103,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 */ @@ -129,9 +130,9 @@ 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"); if (fp == NULL) { @@ -140,26 +141,31 @@ static void helpme(void) { 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; + linebuf[strlen(linebuf)-1] = '\0'; // No \n at end + prout(linebuf); + } fclose(fp); } @@ -323,7 +329,7 @@ static void makemoves(void) { events(); if (alldone) break; // Events did us in } - if (d.galaxy[quadx][quady] == 1000) { // Galaxy went Nova! + if (game.state.galaxy[quadx][quady] == 1000) { // Galaxy went Nova! atover(0); continue; } @@ -331,7 +337,7 @@ static void makemoves(void) { if (hitme && justin==0) { attack(2); if (alldone) break; - if (d.galaxy[quadx][quady] == 1000) { // went NOVA! + if (game.state.galaxy[quadx][quady] == 1000) { // went NOVA! atover(0); hitme = TRUE; continue; @@ -373,13 +379,13 @@ int main(int argc, char **argv) { skip(1); if (tourn && alldone) { - printf("Do you want your score recorded?"); + proutn("Do you want your score recorded?"); if (ja()) { chew2(); freeze(FALSE); } } - printf("Do you want to play again?"); + proutn("Do you want to play again?"); if (!ja()) break; } skip(1); @@ -407,20 +413,20 @@ void cramen(int i) { proutn(s); } -void cramlc(int key, int x, int y) { - if (key == 1) proutn(" Quadrant"); - else if (key == 2) proutn(" Sector"); - proutn(" "); - crami(x, 1); - proutn(" - "); - crami(y, 1); +char *cramlc(enum loctype key, int x, int y) { + static char buf[32]; + buf[0] = '\0'; + if (key == quadrant) strcpy(buf, "Quadrant "); + else if (key == sector) strcpy(buf, "Sector "); + sprintf(buf+strlen(buf), "%d-%d", x, y); + return buf; } void crmena(int i, int enemy, int key, int x, int y) { if (i == 1) proutn("***"); cramen(enemy); proutn(" at"); - cramlc(key, x, y); + proutn(cramlc(key, x, y)); } void crmshp(void) { @@ -530,18 +536,6 @@ int ja(void) { } } -void cramf(double x, int w, int d) { - char buf[64]; - sprintf(buf, "%*.*f", w, d, x); - proutn(buf); -} - -void crami(int i, int w) { - char buf[16]; - sprintf(buf, "%*d", w, i); - proutn(buf); -} - double square(double i) { return i*i; } static void clearscreen(void) { @@ -591,22 +585,34 @@ void skip(int i) { } -void proutn(char *s) { - fputs(s, stdout); +void proutn(char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + vprintf(fmt, ap); + va_end(ap); } -void prout(char *s) { - proutn(s); - skip(1); +void prout(char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + vprintf(fmt, ap); + va_end(ap); + skip(1); } -void prouts(char *s) { +void prouts(char *fmt, ...) { clock_t endTime; + char *s, buf[BUFSIZ]; /* print slowly! */ - while (*s) { + 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++); + putchar(*s); fflush(stdout); } } @@ -637,7 +643,7 @@ void debugme(void) { proutn("Reset damage? "); if (ja() != 0) { int i; - for (i=0; i <= ndevice; i++) if (damage[i] > 0.0) damage[i] = 0.0; + for (i=0; i <= NDEVICES; i++) if (damage[i] > 0.0) damage[i] = 0.0; stdamtim = 1e30; } proutn("Toggle idebug? "); @@ -649,7 +655,7 @@ void debugme(void) { proutn("Cause selective damage? "); if (ja() != 0) { int i, key; - for (i=1; i <= ndevice; i++) { + for (i=1; i <= NDEVICES; i++) { proutn("Kill "); proutn(device[i]); proutn("? "); @@ -657,7 +663,7 @@ void debugme(void) { key = scan(); if (key == IHALPHA && isit("y")) { damage[i] = 10.0; - if (i == DRADIO) stdamtim = d.date; + if (i == DRADIO) stdamtim = game.state.date; } } } @@ -676,12 +682,12 @@ void debugme(void) { case FSCMOVE: proutn("SC Move "); break; case FSCDBAS: proutn("SC Base Destroy "); break; } - cramf(future[i]-d.date, 8, 2); + proutn("%.2f", future[i]-game.state.date); chew(); proutn(" ?"); key = scan(); if (key == IHREAL) { - future[i] = d.date + aaitem; + future[i] = game.state.date + aaitem; } } chew();