if (nsteps < 1) nsteps = 1; /* This shouldn't be necessary */\r
#ifdef DEBUG\r
if (idebug) {\r
- proutn("NSTEPS = ");\r
- crami(nsteps, 1);\r
- skip(1);\r
+ prout("NSTEPS = %d", nsteps);\r
}\r
#endif\r
/* Compute preferred values of delta X and Y */\r
for (ll = 1; ll <= nsteps; ll++) {\r
#ifdef DEBUG\r
if (idebug) {\r
- crami(ll,2);\r
- skip(1);\r
+ prout("%d", ll);\r
}\r
#endif\r
/* Check if preferred position available */\r
crmshp();\r
prout(" heavily damaged.");\r
icas = 10.0+20.0*Rand();\r
- proutn("***Sickbay reports ");\r
- crami(icas, 1);\r
- prout(" casualties.");\r
+ prout("***Sickbay reports %d casualties", icas);\r
casual += icas;\r
for (l=1; l <= NDEVICES; l++) {\r
if (l == DDRAY) continue; // Don't damage deathray \r
if (hit > hitmax) hitmax = hit;\r
hittot += hit;\r
fry(hit);\r
- printf("Hit %g energy %g\n", hit, energy);\r
+ prout("Hit %g energy %g", hit, energy);\r
energy -= hit;\r
}\r
if (energy <= 0) {\r
else {\r
/* Print message if starship suffered hit(s) */\r
skip(1);\r
- proutn("Energy left ");\r
- cramf(energy, 0, 2);\r
- proutn(" shields ");\r
- if (shldup) proutn("up, ");\r
- else if (game.damage[DSHIELD] == 0) proutn("down, ");\r
+ proutn("Energy left %2d shields ", (int)energy);\r
+ if (shldup) proutn("up ");\r
+ else if (game.damage[DSHIELD] == 0) proutn("down ");\r
else proutn("damaged, ");\r
}\r
- crami(percent, 1);\r
- proutn("% torpedoes left ");\r
- crami(torps, 1);\r
- skip(1);\r
+ prout("%d%%, torpedoes left %d", percent, torps);\r
/* Check if anyone was hurt */\r
if (hitmax >= 200 || hittot >= 500) {\r
int icas= hittot*Rand()*0.015;\r
if (icas >= 2) {\r
skip(1);\r
- proutn("Mc Coy- \"Sickbay to bridge. We suffered ");\r
- crami(icas, 1);\r
- prout(" casualties");\r
+ prout("Mc Coy- \"Sickbay to bridge. We suffered %d casualties", icas);\r
prout(" in that last attack.\"");\r
casual += icas;\r
}\r
return;\r
}\r
else if (key == IHEOL) {\r
- crami(torps,1);\r
- prout(" torpedoes left.");\r
+ prout("%d torpedoes left.", torps);\r
proutn("Number of torpedoes to fire- ");\r
key = scan();\r
}\r
if (i == 1 && key == IHEOL) {\r
/* prompt for each one */\r
for (i = 1; i <= n; i++) {\r
- proutn("Target sector for torpedo number");\r
- crami(i, 2);\r
- proutn("- ");\r
+ proutn("Target sector for torpedo number %d- ", i);\r
key = scan();\r
if (key != IHREAL) {\r
huh();\r
/* misfire! */\r
r = (Rand()+1.2) * r;\r
if (n>1) {\r
- prouts("***TORPEDO NUMBER");\r
- crami(i, 2);\r
- prouts(" MISFIRES.");\r
+ prouts("***TORPEDO NUMBER %d MISFIRES", i);\r
}\r
else prouts("***TORPEDO MISFIRES.");\r
skip(1);\r
if (shldup != 0 || condit == IHDOCKED) r *= 1.0 + 0.0001*shield;\r
if (n != 1) {\r
skip(1);\r
- proutn("Track for torpedo number");\r
- crami(i, 2);\r
- proutn("- ");\r
+ proutn("Track for torpedo number %d- ", i);\r
}\r
else {\r
skip(1);\r
if (icas) {\r
skip(1);\r
prout("McCoy to bridge- \"Severe radiation burns, Jim.");\r
- proutn(" ");\r
- crami(icas, 1);\r
- prout(" casualties so far.\"");\r
+ prout(" %d casualties so far.\"", icas);\r
casual -= icas;\r
}\r
skip(1);\r
int irec=(fabs(game.kpower[k])/(PHASEFAC*pow(0.9,game.kdist[k])))*\r
(1.01+0.05*Rand()) + 1.0;\r
kz = k;\r
- proutn("(");\r
- crami(irec, 1);\r
- proutn(") ");\r
+ proutn("(%d)", irec);\r
}\r
proutn("units to fire at ");\r
crmena(0, ienm, 2, ii, jj);\r
int igotit = 0;\r
alldone = 1;\r
skip(3);\r
- printf("It is stardate %.1f .\n\n", game.state.date);\r
+ prout("It is stardate %.1f.", game.state.date);\r
+ prout("");\r
switch (ifin) {\r
case FWON: // Game has been won\r
if (game.state.nromrem != 0)\r
- printf("The remaining %d Romulans surrender to Starfleet Command.\n",\r
+ prout("The remaining %d Romulans surrender to Starfleet Command.",\r
game.state.nromrem);\r
\r
prout("You have smashed the Klingon invasion fleet and saved");\r
skip(2);\r
prout("Your score --");\r
if (game.state.nromkl)\r
- printf("%6d Romulans destroyed %5d\n",\r
+ prout("%6d Romulans destroyed %5d",\r
game.state.nromkl,20*game.state.nromkl);\r
if (game.state.nromrem)\r
- printf("%6d Romulans captured %5d\n",\r
+ prout("%6d Romulans captured %5d",\r
game.state.nromrem, game.state.nromrem);\r
if (game.state.killk)\r
- printf("%6d ordinary Klingons destroyed %5d\n",\r
+ prout("%6d ordinary Klingons destroyed %5d",\r
game.state.killk, 10*game.state.killk);\r
if (game.state.killc)\r
- printf("%6d Klingon commanders destroyed %5d\n",\r
+ prout("%6d Klingon commanders destroyed %5d",\r
game.state.killc, 50*game.state.killc);\r
if (game.state.nsckill)\r
- printf("%6d Super-Commander destroyed %5d\n",\r
+ prout("%6d Super-Commander destroyed %5d",\r
game.state.nsckill, 200*game.state.nsckill);\r
if (ithperd)\r
- printf("%6.2f Klingons per stardate %5d\n",\r
+ prout("%6.2f Klingons per stardate %5d",\r
perdate, ithperd);\r
if (game.state.starkl)\r
- printf("%6d stars destroyed by your action %5d\n",\r
+ prout("%6d stars destroyed by your action %5d",\r
game.state.starkl, -5*game.state.starkl);\r
if (game.state.nplankl)\r
- printf("%6d planets destroyed by your action %5d\n",\r
+ prout("%6d planets destroyed by your action %5d",\r
game.state.nplankl, -10*game.state.nplankl);\r
if (game.state.basekl)\r
- printf("%6d bases destroyed by your action %5d\n",\r
+ prout("%6d bases destroyed by your action %5d",\r
game.state.basekl, -100*game.state.basekl);\r
if (nhelp)\r
- printf("%6d calls for help from starbase %5d\n",\r
+ prout("%6d calls for help from starbase %5d",\r
nhelp, -45*nhelp);\r
if (casual)\r
- printf("%6d casualties incurred %5d\n",\r
+ prout("%6d casualties incurred %5d",\r
casual, -casual);\r
if (klship)\r
- printf("%6d ship(s) lost or destroyed %5d\n",\r
+ prout("%6d ship(s) lost or destroyed %5d",\r
klship, -100*klship);\r
if (alive==0)\r
prout("Penalty for getting yourself killed -200");\r
case 4: proutn("Expert game "); break;\r
case 5: proutn("Emeritus game"); break;\r
}\r
- printf(" %5d\n", iwon);\r
+ prout(" %5d", iwon);\r
}\r
skip(2);\r
- printf("TOTAL SCORE %5d\n", iscore);\r
+ prout("TOTAL SCORE %5d", iscore);\r
}\r
\r
void plaque(void) {\r
skip(2);\r
\r
while (fp == NULL) {\r
- printf("File or device name for your plaque:");\r
+ proutn("File or device name for your plaque:");\r
fgets(winner, 128, stdin);\r
winner[strlen(winner)-1] = '\0';\r
fp = fopen(winner, "w");\r
if (fp==NULL) {\r
- printf("Invalid name.\n");\r
+ prout("Invalid name.");\r
}\r
}\r
\r
- printf("Enter name to go on plaque (up to 30 characters):");\r
+ proutn("Enter name to go on plaque (up to 30 characters):");\r
fgets(winner, 128, stdin);\r
winner[strlen(winner)-1] = '\0';\r
winner[30] = '\0';\r
prout("We can't do it, Captain. We haven't the energy.");\r
}\r
else {\r
- proutn("We haven't the energy, but we could do it at warp ");\r
- crami(iwarp, 1);\r
- if (shldup)\r
- prout(",\nif you'll lower the shields.");\r
+ proutn("We haven't the energy, but we could do it at warp %d", iwarp);\r
+ if (shldup) {\r
+ prout(",");\r
+ prout("if you'll lower the shields.");\r
+ }\r
else\r
prout(".");\r
}\r
\r
if (key == IHEOL) {\r
/* slow mode, so let Kirk know how many probes there are left */\r
- crami(nprobes,1);\r
- prout(nprobes==1 ? " probe left." : " probes left.");\r
+ prout(nprobes==1 ? "%d probe left." : "%d probes left.", nprobes);\r
proutn("Are you sure you want to fire a probe? ");\r
if (ja()==0) return;\r
}\r
prout(" is still operational.\"");\r
}\r
else {\r
- prout(" has been rendered disfunctional.\"");\r
+ prout(" has been rendered nonfunctional.\"");\r
game.damage[DDRAY] = 39.95;\r
}\r
return;\r
case 5: s3="emeritus"; break;\r
default: s3="skilled"; break;\r
}\r
- printf("\nYou %s playing a %s%s %s game.\n",\r
+ prout("");\r
+ prout("You %s playing a %s%s %s game.",\r
alldone? "were": "are now", s1, s2, s3);\r
if (skill>3 && thawed && !alldone) prout("No plaque is allowed.");\r
- if (tourn) printf("This is tournament game %d.\n", tourn);\r
- if (f) printf("Your secret password is \"%s\"\n",game.passwd);\r
- printf("%d of %d Klingons have been killed",\r
+ if (tourn) prout("This is tournament game %d.", tourn);\r
+ if (f) prout("Your secret password is \"%s\"",game.passwd);\r
+ proutn("%d of %d Klingons have been killed",\r
game.state.killk+game.state.killc+game.state.nsckill, inkling);\r
- if (game.state.killc) printf(", including %d Commander%s.\n", game.state.killc, game.state.killc==1?"":"s");\r
+ if (game.state.killc) prout(", including %d Commander%s.", game.state.killc, game.state.killc==1?"":"s");\r
else if (game.state.killk+game.state.nsckill > 0) prout(", but no Commanders.");\r
else prout(".");\r
- if (skill > 2) printf("The Super Commander has %sbeen destroyed.\n",\r
+ if (skill > 2) prout("The Super Commander has %sbeen destroyed.",\r
game.state.nscrem?"not ":"");\r
if (game.state.rembase != inbase) {\r
proutn("There ");\r
if (inbase-game.state.rembase==1) proutn("has been 1 base");\r
else {\r
- proutn("have been ");\r
- crami(inbase-game.state.rembase, 1);\r
- proutn(" bases");\r
+ proutn("have been %d bases", inbase-game.state.rembase);\r
}\r
- proutn(" destroyed, ");\r
- crami(game.state.rembase, 1);\r
- prout(" remaining.");\r
+ prout(" destroyed, %d remaining.", game.state.rembase);\r
}\r
- else printf("There are %d bases.\n", inbase);\r
+ else prout("There are %d bases.", inbase);\r
if (game.damage[DRADIO] == 0.0 || condit == IHDOCKED || iseenit) {\r
/* Don't report this if not seen and\r
either the radio is dead or not at base! */\r
attakreport();\r
iseenit = 1;\r
}\r
- if (casual) printf("%d casualt%s suffered so far.\n",\r
+ if (casual) prout("%d casualt%s suffered so far.",\r
casual, casual==1? "y" : "ies");\r
- if (nhelp) printf("There were %d call%s for help.\n",\r
+ if (nhelp) prout("There were %d call%s for help.",\r
nhelp, nhelp==1 ? "" : "s");\r
if (ship == IHE) {\r
proutn("You have ");\r
- if (nprobes) crami(nprobes,1);\r
+ if (nprobes) proutn("%d", nprobes);\r
else proutn("no");\r
proutn(" deep space probe");\r
if (nprobes!=1) proutn("s");\r
ai *= 2.0;\r
i++;\r
}\r
- printf("Dilithium crystals have been used %d time%s.\n",\r
+ prout("Dilithium crystals have been used %d time%s.",\r
i, i==1? "" : "s");\r
}\r
}\r
for (x = quadx-1; x <= quadx+1; x++) {\r
for (y = quady-1; y <= quady+1; y++) {\r
if (x == 0 || x > 8 || y == 0 || y > 8)\r
- printf(" -1");\r
+ proutn(" -1");\r
else {\r
- printf("%5d", game.state.galaxy[x][y]);\r
+ proutn("%5d", game.state.galaxy[x][y]);\r
game.starch[x][y] = game.damage[DRADIO] > 0 ? game.state.galaxy[x][y]+1000 :1;\r
}\r
}\r
prout(" IN FLIGHT DOCKED");\r
jdam = TRUE;\r
}\r
- printf(" %16s ", device[i]);\r
+ proutn(" %16s ", device[i]);\r
cramf(game.damage[i]+0.05, 8, 2);\r
proutn(" ");\r
cramf(docfac*game.damage[i]+0.005, 8, 2);\r
\r
prout(" 1 2 3 4 5 6 7 8");\r
prout(" ----------------------------------------");\r
- if (nn==0) prout(" -");\r
+ /* if (nn==0) prout(" -"); */\r
for (i = 1; i <= 8; i++) {\r
- printf("%d -", i);\r
+ proutn("%d -", i);\r
for (j = 1; j <= 8; j++) {\r
if (game.starch[i][j] < 0)\r
- printf(" .1.");\r
+ proutn(" .1.");\r
else if (game.starch[i][j] == 0)\r
- printf(" ...");\r
+ proutn(" ...");\r
else if (game.starch[i][j] > 999)\r
- printf("%5d", game.starch[i][j]-1000);\r
+ proutn("%5d", game.starch[i][j]-1000);\r
else\r
- printf("%5d", game.state.galaxy[i][j]);\r
+ proutn("%5d", game.state.galaxy[i][j]);\r
}\r
prout(" -");\r
}\r
break;\r
case 2: // REQUEST\r
while (scan() == IHEOL)\r
- printf("Information desired? ");\r
+ proutn("Information desired? ");\r
chew();\r
for (k = 1; k <= 10; k++)\r
if (strncmp(citem,requests[k],min(2,strlen(citem)))==0)\r
for (i = 1; i <= 10; i++) {\r
int jj = (k!=0 ? k : i);\r
if (leftside) {\r
- printf("%2d ", i);\r
+ proutn("%2d ", i);\r
for (j = 1; j <= 10; j++) {\r
if (goodScan || (abs(i-sectx)<= 1 && abs(j-secty) <= 1))\r
- printf("%c ",game.quad[i][j]);\r
+ proutn("%c ",game.quad[i][j]);\r
else\r
- printf("- ");\r
+ proutn("- ");\r
}\r
}\r
if (rightside) {\r
switch (jj) {\r
case 1:\r
- printf(" Stardate %.1f", game.state.date);\r
+ proutn(" Stardate %.1f", game.state.date);\r
break;\r
case 2:\r
if (condit != IHDOCKED) newcnd();\r
case IHYELLOW: cp = "YELLOW"; break;\r
case IHDOCKED: cp = "DOCKED"; break;\r
}\r
- printf(" Condition %s", cp);\r
+ proutn(" Condition %s", cp);\r
break;\r
case 3:\r
- printf(" Position ");\r
+ proutn(" Position ");\r
cramlc(0, quadx, quady);\r
- putchar(',');\r
+ proutn(",");\r
cramlc(0, sectx, secty);\r
break;\r
case 4:\r
- printf(" Life Support ");\r
+ proutn(" Life Support ");\r
if (game.damage[DLIFSUP] != 0.0) {\r
if (condit == IHDOCKED)\r
- printf("DAMAGED, supported by starbase");\r
+ proutn("DAMAGED, supported by starbase");\r
else\r
- printf("DAMAGED, reserves=%4.2f", lsupres);\r
+ proutn("DAMAGED, reserves=%4.2f", lsupres);\r
}\r
else\r
- printf("ACTIVE");\r
+ proutn("ACTIVE");\r
break;\r
case 5:\r
- printf(" Warp Factor %.1f", warpfac);\r
+ proutn(" Warp Factor %.1f", warpfac);\r
break;\r
case 6:\r
- printf(" Energy %.2f", energy);\r
+ proutn(" Energy %.2f", energy);\r
break;\r
case 7:\r
- printf(" Torpedoes %d", torps);\r
+ proutn(" Torpedoes %d", torps);\r
break;\r
case 8:\r
- printf(" Shields ");\r
+ proutn(" Shields ");\r
if (game.damage[DSHIELD] != 0)\r
- printf("DAMAGED,");\r
+ proutn("DAMAGED,");\r
else if (shldup)\r
- printf("UP,");\r
+ proutn("UP,");\r
else\r
- printf("DOWN,");\r
- printf(" %d%% %.1f units",\r
+ proutn("DOWN,");\r
+ proutn(" %d%% %.1f units",\r
(int)((100.0*shield)/inshld + 0.5), shield);\r
break;\r
case 9:\r
- printf(" Klingons Left %d", game.state.remkl);\r
+ proutn(" Klingons Left %d", game.state.remkl);\r
break;\r
case 10:\r
- printf(" Time Left %.2f", game.state.remtime);\r
+ proutn(" Time Left %.2f", game.state.remtime);\r
break;\r
}\r
\r
skip(1);\r
return;\r
}\r
+ strcpy(game.magic, SSTMAGIC);\r
fwrite(&game, sizeof(game), 1, fp);\r
\r
fclose(fp);\r
return;\r
}\r
fread(&game, sizeof(game), 1, fp);\r
+ if (strcmp(game.magic, SSTMAGIC)) {\r
+ prout("Game file format is bad, should begin with " SSTMAGIC);\r
+ skip(1);\r
+ return;\r
+ }\r
\r
fclose(fp);\r
\r
if (distq < 6.0*(6-inbase) && Rand() < 0.75) {\r
contflag = TRUE;\r
#ifdef DEBUG\r
- printf("DEBUG: Abandoning base #%d at %d-%d\n", i, ix, iy);\r
+ proutn("DEBUG: Abandoning base #%d at %d-%d\n", i, ix, iy);\r
#endif\r
break;\r
}\r
#ifdef DEBUG\r
else if (distq < 6.0 * (6-inbase)) {\r
- printf("DEBUG: saving base #%d, close to #%d\n", i, j);\r
+ proutn("DEBUG: saving base #%d, close to #%d\n", i, j);\r
}\r
#endif\r
}\r
game.state.snap = 0;\r
\r
if (skill == 1) {\r
- printf("It is stardate %d. The Federation is being attacked by\n",\r
+ prout("It is stardate %d. The Federation is being attacked by",\r
(int)game.state.date);\r
- printf("a deadly Klingon invasion force. As captain of the United\n"\r
- "Starship U.S.S. Enterprise, it is your mission to seek out\n"\r
- "and destroy this invasion force of %d battle cruisers.\n",\r
+ prout("a deadly Klingon invasion force. As captain of the United");\r
+ prout("Starship U.S.S. Enterprise, it is your mission to seek out");\r
+ prout("and destroy this invasion force of %d battle cruisers.",\r
inkling);\r
- printf("You have an initial allotment of %d stardates to complete\n"\r
- "your mission. As you proceed you may be given more time.\n\n"\r
- "You will have %d supporting starbases.\n"\r
- "Starbase locations- ",\r
- (int)intime, inbase);\r
+ prout("You have an initial allotment of %d stardates to complete", (int)intime);\r
+ prout("your mission. As you proceed you may be given more time.");\r
+ prout("");\r
+ prout("You will have %d supporting starbases.", inbase);\r
+ proutn("Starbase locations- ");\r
}\r
else {\r
- printf("Stardate %d.\n\n"\r
- "%d Klingons.\nAn unknown number of Romulans\n",\r
- (int)game.state.date, inkling);\r
- if (game.state.nscrem) printf("and one (GULP) Super-Commander.\n");\r
- printf("%d stardates\n%d starbases in ",(int)intime, inbase);\r
+ prout("Stardate %d.", (int)game.state.date);\r
+ prout("");\r
+ prout("%d Klingons.", inkling);\r
+ prout("An unknown number of Romulans.");\r
+ if (game.state.nscrem) prout("and one (GULP) Super-Commander.");\r
+ prout("%d stardates.",(int)intime);\r
+ proutn("%d starbases in ", inbase);\r
}\r
for (i = 1; i <= inbase; i++) {\r
cramlc(0, game.state.baseqx[i], game.state.baseqy[i]);\r
#define INCLUDED // Define externs here\r
#include "sst.h"\r
#include <ctype.h>\r
+#include <stdarg.h>\r
#ifdef MSDOS\r
#include <dos.h>\r
#endif\r
skip(1);\r
\r
if (tourn && alldone) {\r
- printf("Do you want your score recorded?");\r
+ proutn("Do you want your score recorded?");\r
if (ja()) {\r
chew2();\r
freeze(FALSE);\r
}\r
}\r
- printf("Do you want to play again?");\r
+ proutn("Do you want to play again?");\r
if (!ja()) break;\r
}\r
skip(1);\r
void cramlc(int key, int x, int y) {\r
if (key == 1) proutn(" Quadrant");\r
else if (key == 2) proutn(" Sector");\r
- proutn(" ");\r
- crami(x, 1);\r
- proutn(" - ");\r
- crami(y, 1);\r
+ proutn(" %d - %d", x, y);\r
}\r
\r
void crmena(int i, int enemy, int key, int x, int y) {\r
proutn(buf);\r
}\r
\r
-void crami(int i, int w) {\r
- char buf[16];\r
- sprintf(buf, "%*d", w, i);\r
- proutn(buf);\r
-}\r
-\r
double square(double i) { return i*i; }\r
\r
static void clearscreen(void) {\r
}\r
\r
\r
-void proutn(char *s) {\r
- fputs(s, stdout);\r
+void proutn(char *fmt, ...) {\r
+ va_list ap;\r
+ va_start(ap, fmt);\r
+ vprintf(fmt, ap);\r
+ va_end(ap);\r
}\r
\r
-void prout(char *s) {\r
- proutn(s);\r
- skip(1);\r
+void prout(char *fmt, ...) {\r
+ va_list ap;\r
+ va_start(ap, fmt);\r
+ vprintf(fmt, ap);\r
+ va_end(ap);\r
+ skip(1);\r
}\r
\r
-void prouts(char *s) {\r
+void prouts(char *fmt, ...) {\r
clock_t endTime;\r
+ char *s, buf[BUFSIZ];\r
/* print slowly! */\r
- while (*s) {\r
+ va_list ap;\r
+ va_start(ap, fmt);\r
+ vsprintf(buf, fmt, ap);\r
+ va_end(ap);\r
+ skip(1);\r
+ for (s = buf; *s; s++) {\r
endTime = clock() + CLOCKS_PER_SEC*0.05;\r
while (clock() < endTime) ;\r
- putchar(*s++);\r
+ putchar(*s);\r
fflush(stdout);\r
}\r
}\r
void chew(void);\r
void chew2(void);\r
void skip(int);\r
-void prout(char *s);\r
-void proutn(char *s);\r
+void prout(char *, ...);\r
+void proutn(char *, ...);\r
void stars(void);\r
void newqad(int);\r
int ja(void);\r
void movcom(void);\r
void torpedo(double, double, int, int, double *);\r
void cramf(double, int, int);\r
-void crami(int, int);\r
void huh(void);\r
void pause(int);\r
void nova(int, int);\r
void snova(int, int);\r
void scom(int *);\r
void hittem(double *);\r
-void prouts(char *);\r
+void prouts(char *, ...);\r
int isit(char *);\r
void preport(void);\r
void orbit(void);\r