X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=blobdiff_plain;f=sst.c;h=653e06be826b8a71d4950682fa2ad04fb78f1267;hp=31202254ae78c2a785f392a4c7d46970522c777b;hb=7d27c8befdb5de9a50ff4af88e764c8336bc1797;hpb=48763357ef69f0b711fc332b13e2170ab914d881 diff --git a/sst.c b/sst.c index 3120225..653e06b 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 @@ -373,13 +374,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 +408,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 +531,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 +580,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 +638,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 +650,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("? "); @@ -676,7 +677,7 @@ void debugme(void) { case FSCMOVE: proutn("SC Move "); break; case FSCDBAS: proutn("SC Base Destroy "); break; } - cramf(future[i]-game.state.date, 8, 2); + proutn("%82.2f", future[i]-game.state.date); chew(); proutn(" ?"); key = scan();