X-Git-Url: https://jxself.org/git/?p=super-star-trek.git;a=blobdiff_plain;f=sst.c;h=653e06be826b8a71d4950682fa2ad04fb78f1267;hp=55066eb7fdeaa9b487647493486b2c434834a739;hb=7d27c8befdb5de9a50ff4af88e764c8336bc1797;hpb=e1d80424873d901a732bf81c3a7ecc564636375e diff --git a/sst.c b/sst.c index 55066eb..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 @@ -323,7 +324,7 @@ static void makemoves(void) { events(); if (alldone) break; // Events did us in } - if (state.galaxy[quadx][quady] == 1000) { // Galaxy went Nova! + if (game.state.galaxy[quadx][quady] == 1000) { // Galaxy went Nova! atover(0); continue; } @@ -331,7 +332,7 @@ static void makemoves(void) { if (hitme && justin==0) { attack(2); if (alldone) break; - if (state.galaxy[quadx][quady] == 1000) { // went NOVA! + if (game.state.galaxy[quadx][quady] == 1000) { // went NOVA! atover(0); hitme = TRUE; continue; @@ -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("? "); @@ -657,7 +658,7 @@ void debugme(void) { key = scan(); if (key == IHALPHA && isit("y")) { damage[i] = 10.0; - if (i == DRADIO) stdamtim = state.date; + if (i == DRADIO) stdamtim = game.state.date; } } } @@ -676,12 +677,12 @@ void debugme(void) { case FSCMOVE: proutn("SC Move "); break; case FSCDBAS: proutn("SC Base Destroy "); break; } - cramf(future[i]-state.date, 8, 2); + proutn("%82.2f", future[i]-game.state.date); chew(); proutn(" ?"); key = scan(); if (key == IHREAL) { - future[i] = state.date + aaitem; + future[i] = game.state.date + aaitem; } } chew();