Get rid of DEBUG, the instrumentation is cheap and we want to cut down
on the possibilities for unanticipated logic changes due to
configuration vagaries. Take the debugging bit out of the game
structure. Start on the logger.
if (game.condit==IHDOCKED && (game.options & OPTION_BASE)) /* protected by base -- back off ! */
motion -= game.skill*(2.0-square(Rand()));
}
if (game.condit==IHDOCKED && (game.options & OPTION_BASE)) /* protected by base -- back off ! */
motion -= game.skill*(2.0-square(Rand()));
}
-#ifdef DEBUG
- if (game.idebug) {
- proutn("MOTION = %1.2f", motion);
- proutn(" FORCES = %1.2f", forces);
- }
-#endif
+ if (idebug)
+ proutn("=== MOTION = %1.2f, FORCES = %1.2f, ", motion, forces);
/* don't move if no motion */
if (motion==0) return;
/* Limit motion according to skill */
/* don't move if no motion */
if (motion==0) return;
/* Limit motion according to skill */
if (motion > 0 && nsteps > mdist) nsteps = mdist; /* don't overshoot */
if (nsteps > QUADSIZE) nsteps = QUADSIZE; /* This shouldn't be necessary */
if (nsteps < 1) nsteps = 1; /* This shouldn't be necessary */
if (motion > 0 && nsteps > mdist) nsteps = mdist; /* don't overshoot */
if (nsteps > QUADSIZE) nsteps = QUADSIZE; /* This shouldn't be necessary */
if (nsteps < 1) nsteps = 1; /* This shouldn't be necessary */
-#ifdef DEBUG
- if (game.idebug) {
- prout("NSTEPS = %d", nsteps);
+ if (idebug) {
+ proutn("NSTEPS = %d:", nsteps);
/* Compute preferred values of delta X and Y */
mx = game.sector.x - com.x;
my = game.sector.y - com.y;
/* Compute preferred values of delta X and Y */
mx = game.sector.x - com.x;
my = game.sector.y - com.y;
next = com;
/* main move loop */
for (ll = 0; ll < nsteps; ll++) {
next = com;
/* main move loop */
for (ll = 0; ll < nsteps; ll++) {
-#ifdef DEBUG
- if (game.idebug) {
- prout("%d", ll+1);
- }
-#endif
+ if (idebug)
+ proutn(" %d", ll+1);
/* Check if preferred position available */
lookx = next.x + mx;
looky = next.y + my;
/* Check if preferred position available */
lookx = next.x + mx;
looky = next.y + my;
if (success) {
next.x = lookx;
next.y = looky;
if (success) {
next.x = lookx;
next.y = looky;
-#ifdef DEBUG
- if (game.idebug) {
- prout(cramlc(neither, next));
- }
-#endif
+ if (idebug)
+ proutn(cramlc(neither, next));
}
else break; /* done early */
}
else break; /* done early */
+ if (idebug)
+ prout("");
/* Put commander in place within same quadrant */
game.quad[com.x][com.y] = IHDOT;
game.quad[next.x][next.y] = ienm;
/* Put commander in place within same quadrant */
game.quad[com.x][com.y] = IHDOT;
game.quad[next.x][next.y] = ienm;
-#ifdef DEBUG
- if (game.idebug) prout("MOVCOM");
-#endif
+ if (idebug) prout("== MOVCOM");
/* Figure out which Klingon is the commander (or Supercommander)
and do move */
/* Figure out which Klingon is the commander (or Supercommander)
and do move */
-static int movescom(coord iq, int flag, int *ipage)
+static bool movescom(coord iq, int flag, int *ipage)
for_starbases(i)
if (game.state.baseq[i].x==iq.x && game.state.baseq[i].y==iq.y) return 1;
}
for_starbases(i)
if (game.state.baseq[i].x==iq.x && game.state.baseq[i].y==iq.y) return 1;
}
- if (game.justin && !game.iscate) return 1;
+ if (game.justin && !game.iscate) return true;
/* do the move */
game.state.galaxy[game.state.kscmdr.x][game.state.kscmdr.y].klingons--;
game.state.kscmdr = iq;
/* do the move */
game.state.galaxy[game.state.kscmdr.x][game.state.kscmdr.y].klingons--;
game.state.kscmdr = iq;
- return 0; /* looks good! */
+ return false; /* looks good! */
int basetbl[BASEMAX+1];
double bdist[BASEMAX+1];
int flag;
int basetbl[BASEMAX+1];
double bdist[BASEMAX+1];
int flag;
-#ifdef DEBUG
- if (game.idebug) prout("SCOM");
-#endif
+
+ if (idebug) prout("== SCOM");
/* Decide on being active or passive */
flag = ((NKILLC+NKILLK)/(game.state.date+0.01-game.indate) < 0.1*game.skill*(game.skill+1.0) ||
/* Decide on being active or passive */
flag = ((NKILLC+NKILLK)/(game.state.date+0.01-game.indate) < 0.1*game.skill*(game.skill+1.0) ||
/* attack the base */
if (flag) return; /* no, don't attack base! */
game.iseenit = 0;
/* attack the base */
if (flag) return; /* no, don't attack base! */
game.iseenit = 0;
schedule(FSCDBAS, 1.0 +2.0*Rand());
if (is_scheduled(FCDBAS))
postpone(FSCDBAS, scheduled(FCDBAS)-game.state.date);
schedule(FSCDBAS, 1.0 +2.0*Rand());
if (is_scheduled(FCDBAS))
postpone(FSCDBAS, scheduled(FCDBAS)-game.state.date);
}
/* Check for intelligence report */
if (
}
/* Check for intelligence report */
if (
-#ifdef DEBUG
- game.idebug==0 &&
-#endif
(Rand() > 0.2 ||
(game.damage[DRADIO] > 0.0 && game.condit != IHDOCKED) ||
!game.state.galaxy[game.state.kscmdr.x][game.state.kscmdr.y].charted))
(Rand() > 0.2 ||
(game.damage[DRADIO] > 0.0 && game.condit != IHDOCKED) ||
!game.state.galaxy[game.state.kscmdr.x][game.state.kscmdr.y].charted))
game.iattak = 1;
if (game.alldone) return;
game.iattak = 1;
if (game.alldone) return;
-#ifdef DEBUG
- if (game.idebug) prout("ATTACK!");
-#endif
+ if (idebug) prout("=== ATTACK!");
if (game.ithere) movetho();
if (game.ithere) movetho();
int radio_was_broken;
struct quadrant *pdest;
int radio_was_broken;
struct quadrant *pdest;
-#ifdef DEBUG
- if (game.idebug) prout("EVENTS");
-#endif
+ if (idebug) prout("=== EVENTS");
radio_was_broken = (game.damage[DRADIO] != 0.0);
radio_was_broken = (game.damage[DRADIO] != 0.0);
proutn(_(" the starbase in "));
proutn(cramlc(quadrant, game.battle));
prout(_(" has been destroyed by"));
proutn(_(" the starbase in "));
proutn(cramlc(quadrant, game.battle));
prout(_(" has been destroyed by"));
- if (game.isatb==2) prout(_("the Klingon Super-Commander"));
+ if (game.isatb == 2)
+ prout(_("the Klingon Super-Commander"));
else prout(_("a Klingon Commander"));
game.state.chart[game.battle.x][game.battle.y].starbase = false;
}
else prout(_("a Klingon Commander"));
game.state.chart[game.battle.x][game.battle.y].starbase = false;
}
case FSCMOVE: /* Supercommander moves */
schedule(FSCMOVE, 0.2777);
if (game.ientesc+istract==0 &&
case FSCMOVE: /* Supercommander moves */
schedule(FSCMOVE, 0.2777);
if (game.ientesc+istract==0 &&
- game.isatb!=1 &&
- (game.iscate!=1 || game.justin==1)) scom(&ipage);
+ game.isatb != 1 &&
+ (game.iscate != 1 || !game.justin)) scom(&ipage);
break;
case FDSPROB: /* Move deep space probe */
schedule(FDSPROB, 0.01);
break;
case FDSPROB: /* Move deep space probe */
schedule(FDSPROB, 0.01);
-#ifdef DEBUG
- if (game.idebug) {
- proutn("Super nova here?");
+ if (idebug) {
+ proutn("=== Super nova here?");
if (ja()==1) {
nq.x = game.quadrant.x;
nq.y = game.quadrant.y;
}
}
if (ja()==1) {
nq.x = game.quadrant.x;
nq.y = game.quadrant.y;
}
}
}
if (nq.x != game.quadrant.y || nq.y != game.quadrant.y || game.justin != 0) {
}
if (nq.x != game.quadrant.y || nq.y != game.quadrant.y || game.justin != 0) {
void finish(FINTYPE ifin)
{
void finish(FINTYPE ifin)
{
- int igotit = 0;
- game.alldone = 1;
+ bool igotit = false;
+ game.alldone = true;
skip(3);
prout(_("It is stardate %.1f."), game.state.date);
skip(1);
skip(3);
prout(_("It is stardate %.1f."), game.state.date);
skip(1);
prout(_("You have smashed the Klingon invasion fleet and saved"));
prout(_("the Federation."));
prout(_("You have smashed the Klingon invasion fleet and saved"));
prout(_("the Federation."));
if (game.alive) {
double badpt;
badpt = 5.0*game.state.starkl + game.casual + 10.0*game.state.nplankl +
if (game.alive) {
double badpt;
badpt = 5.0*game.state.starkl + game.casual + 10.0*game.state.nplankl +
break;
}
if (game.skill >= SKILL_EXPERT) {
break;
}
if (game.skill >= SKILL_EXPERT) {
- if (game.thawed
-#ifdef DEBUG
- && !game.idebug
-#endif
- )
+ if (game.thawed && !idebug)
prout(_("You cannot get a citation, so..."));
else {
proutn(_("Do you want your Commodore Emeritus Citation printed? "));
prout(_("You cannot get a citation, so..."));
else {
proutn(_("Do you want your Commodore Emeritus Citation printed? "));
(void)endwin();
putchar('\n');
}
(void)endwin();
putchar('\n');
}
+ if (logfp)
+ fclose(logfp);
} else {
fgets(line, max, stdin);
}
} else {
fgets(line, max, stdin);
}
+ if (logfp)
+ fputs(line, logfp);
line[strlen(line)-1] = '\0';
}
line[strlen(line)-1] = '\0';
}
}
/* Decide if time warp will occur */
if (0.5*game.dist*pow(7.0,game.warpfac-10.0) > Rand()) twarp=1;
}
/* Decide if time warp will occur */
if (0.5*game.dist*pow(7.0,game.warpfac-10.0) > Rand()) twarp=1;
-#ifdef DEBUG
- if (game.idebug &&game.warpfac==10 && twarp==0) {
+ if (idebug && game.warpfac==10 && twarp==0) {
- proutn("Force time warp? ");
+ proutn("=== Force time warp? ");
if (blooey || twarp) {
/* If time warp or engine damage, check path */
/* If it is obstructed, don't do warp or damage */
if (blooey || twarp) {
/* If time warp or engine damage, check path */
/* If it is obstructed, don't do warp or damage */
+ bool iknow = false;
+ int i;
skip(1);
chew();
prout("Spock- \"Planet report follows, Captain.\"");
skip(1);
chew();
prout("Spock- \"Planet report follows, Captain.\"");
for (i = 0; i < game.inplan; i++) {
if ((game.state.plnets[i].known != unknown
&& game.state.plnets[i].crystals != 0)
for (i = 0; i < game.inplan; i++) {
if ((game.state.plnets[i].known != unknown
&& game.state.plnets[i].crystals != 0)
-#ifdef DEBUG
- || ( game.idebug && game.state.plnets[i].x !=0)
-#endif
+ || (idebug && game.state.plnets[i].w.x !=0)
- iknow = 1;
-#ifdef DEBUG
- if (game.idebug && game.state.plnets[i].known==unknown) proutn("(Unknown) ");
-#endif
+ iknow = true;
+ if (idebug && game.state.plnets[i].known==unknown)
+ proutn("(Unknown) ");
proutn(cramlc(quadrant, game.state.plnets[i].w));
proutn(" class ");
proutn(classes[game.state.plnets[i].pclass]);
proutn(cramlc(quadrant, game.state.plnets[i].w));
proutn(" class ");
proutn(classes[game.state.plnets[i].pclass]);
} else {
if (is_scheduled(FCDBAS))
proutn("Base in %i - %i attacked by C. Alive until %.1f", game.battle.x, game.battle.y, scheduled(FCDBAS));
} else {
if (is_scheduled(FCDBAS))
proutn("Base in %i - %i attacked by C. Alive until %.1f", game.battle.x, game.battle.y, scheduled(FCDBAS));
proutn("Base in %i - %i attacked by S. Alive until %.1f", game.state.kscmdr.x, game.state.kscmdr.y, scheduled(FSCDBAS));
}
clreol();
proutn("Base in %i - %i attacked by S. Alive until %.1f", game.state.kscmdr.x, game.state.kscmdr.y, scheduled(FSCDBAS));
}
clreol();
{
int i,j, krem, klumper;
int ix, iy;
{
int i,j, krem, klumper;
int ix, iy;
-#ifdef DEBUG
- game.idebug = 0;
-#endif
// Decide how many of everything
if (choose(needprompt)) return; // frozen game
// Prepare the Enterprise
// Decide how many of everything
if (choose(needprompt)) return; // frozen game
// Prepare the Enterprise
double distq = square(ix-game.state.baseq[j].x) + square(iy-game.state.baseq[j].y);
if (distq < 6.0*(BASEMAX+1-game.inbase) && Rand() < 0.75) {
contflag = true;
double distq = square(ix-game.state.baseq[j].x) + square(iy-game.state.baseq[j].y);
if (distq < 6.0*(BASEMAX+1-game.inbase) && Rand() < 0.75) {
contflag = true;
-#ifdef DEBUG
- prout("DEBUG: Abandoning base #%d at %d-%d", i, ix, iy);
-#endif
+ if (idebug)
+ prout("=== Abandoning base #%d at %d-%d", i, ix, iy);
else if (distq < 6.0 * (BASEMAX+1-game.inbase)) {
else if (distq < 6.0 * (BASEMAX+1-game.inbase)) {
- prout("DEBUG: saving base #%d, close to #%d", i, j);
+ if (idebug)
+ prout("=== Saving base #%d, close to #%d", i, j);
// Position ordinary Klingon Battle Cruisers
krem = game.inkling;
klumper = 0.25*game.skill*(9.0-game.length)+1.0;
// Position ordinary Klingon Battle Cruisers
krem = game.inkling;
klumper = 0.25*game.skill*(9.0-game.length)+1.0;
- if (klumper > 9) klumper = 9; // Can't have more than 9 in quadrant
+ if (klumper > 9)
+ klumper = 9; // Can't have more than 9 in quadrant
do {
double r = Rand();
int klump = (1.0 - r*r)*klumper;
do {
double r = Rand();
int klump = (1.0 - r*r)*klumper;
game.state.galaxy[ix][iy].klingons += klump;
} while (krem > 0);
// Position Klingon Commander Ships
game.state.galaxy[ix][iy].klingons += klump;
} while (krem > 0);
// Position Klingon Commander Ships
for (i = 1; i <= game.incom; i++) {
do {
do { /* IF debugging, put commanders by bases, always! */
for (i = 1; i <= game.incom; i++) {
do {
do { /* IF debugging, put commanders by bases, always! */
if (game.idebug && klumper <= game.inbase) {
ix = game.state.baseq[klumper].x;
iy = game.state.baseq[klumper].y;
klumper++;
}
else
if (game.idebug && klumper <= game.inbase) {
ix = game.state.baseq[klumper].x;
iy = game.state.baseq[klumper].y;
klumper++;
}
else
iran(GALSIZE, &ix, &iy);
}
while ((!game.state.galaxy[ix][iy].klingons && Rand() < 0.75)||
iran(GALSIZE, &ix, &iy);
}
while ((!game.state.galaxy[ix][iy].klingons && Rand() < 0.75)||
prout("\"?");
}
setpassword();
prout("\"?");
}
setpassword();
-#ifdef DEBUG
- if (strcmp(game.passwd, "debug")==0) game.idebug = 1;
-#endif
+ if (strcmp(game.passwd, "debug")==0) {
+ idebug = true;
+ logfp = fopen("sst-input.log", "w");
+ fputs("=== Debug mode enabled\n", stdout);
+ }
// Use parameters to generate initial values of things
game.damfac = 0.5 * game.skill;
// Use parameters to generate initial values of things
game.damfac = 0.5 * game.skill;
if ((game.skill < SKILL_GOOD && Rand() <= 0.02) || /* Lighten up if skill is low */
(game.skill == SKILL_GOOD && Rand() <= 0.05) ||
(game.skill > SKILL_GOOD && Rand() <= 0.08)
if ((game.skill < SKILL_GOOD && Rand() <= 0.02) || /* Lighten up if skill is low */
(game.skill == SKILL_GOOD && Rand() <= 0.05) ||
(game.skill > SKILL_GOOD && Rand() <= 0.08)
- #ifdef DEBUG
- || strcmp(game.passwd, "tholianx")==0
- #endif
) {
do {
game.tholian.x = Rand() > 0.5 ? QUADSIZE : 1;
) {
do {
game.tholian.x = Rand() > 0.5 ? QUADSIZE : 1;
struct game game;
coord thing;
int iqhere, iqengry;
struct game game;
coord thing;
int iqhere, iqengry;
-int iscore, iskill; // Common PLAQ
+int iscore, iskill; // Common PLAQ
double aaitem;
double perdate;
char citem[10];
double aaitem;
double perdate;
char citem[10];
+int seed; // the random-number seed
+bool idebug; // debug mode
+bool randready; // Has the random-number generator initialized?
+FILE *logfp;
char *device[NDEVICES] = {
"S. R. Sensors",
char *device[NDEVICES] = {
"S. R. Sensors",
if (game.ididit) hitme = true;
break;
case DEBUGCMD: // What do we want for debug???
if (game.ididit) hitme = true;
break;
case DEBUGCMD: // What do we want for debug???
break;
case MAYDAY: // Call for help
mayday();
break;
case MAYDAY: // Call for help
mayday();
break;
case QUIT:
game.alldone = 1; // quit the game
break;
case QUIT:
game.alldone = 1; // quit the game
-#ifdef DEBUG
- if (game.idebug) score();
-#endif
break;
case HELP:
helpme(); // get help
break;
case HELP:
helpme(); // get help
commandhook(commands[i].name, false);
for (;;) {
if (game.alldone) break; // Game has ended
commandhook(commands[i].name, false);
for (;;) {
if (game.alldone) break; // Game has ended
-#ifdef DEBUG
- if (game.idebug) prout("2500");
-#endif
if (game.optime != 0.0) {
events();
if (game.alldone) break; // Events did us in
if (game.optime != 0.0) {
events();
if (game.alldone) break; // Events did us in
}
if (game.alldone) break;
}
}
if (game.alldone) break;
}
+ if (idebug) prout("=== Ending");
}
for(;;) { /* Play a game */
setwnd(fullscreen_window);
}
for(;;) { /* Play a game */
setwnd(fullscreen_window);
-#ifdef DEBUG
- prout("INITIAL OPTIONS: %0lx", game.options);
-#endif /* DEBUG */
clrscr();
prelim();
setup(line[0] == '\0');
clrscr();
prelim();
setup(line[0] == '\0');
return -avrage*log(1e-7 + Rand());
}
return -avrage*log(1e-7 + Rand());
}
-double Rand(void) {
- return rand()/(1.0 + (double)RAND_MAX);
+double Rand(void)
+{
+ if (!randready) {
+ if (seed == 0)
+ seed = (unsigned)time(NULL);
+ if (idebug)
+ fprintf(logfp, "seed %d\n", seed);
+ srand(seed);
+ randready = true;
+ }
+ return rand()/(1.0 + (double)RAND_MAX);
}
void iran(int size, int *i, int *j)
}
void iran(int size, int *i, int *j)
void debugme(void)
{
proutn("Reset levels? ");
if (ja() != 0) {
void debugme(void)
{
proutn("Reset levels? ");
if (ja() != 0) {
- if (energy < game.inenrg) energy = game.inenrg;
- shield = game.inshld;
- torps = game.intorps;
+ if (game.energy < game.inenrg) game.energy = game.inenrg;
+ game.shield = game.inshld;
+ game.torps = game.intorps;
game.lsupres = game.inlsr;
}
proutn("Reset damage? ");
game.lsupres = game.inlsr;
}
proutn("Reset damage? ");
}
proutn("Toggle game.idebug? ");
if (ja() != 0) {
}
proutn("Toggle game.idebug? ");
if (ja() != 0) {
- game.idebug = !game.idebug;
- if (game.idebug) prout("Debug output ON");
+ idebug = !idebug;
+ if (idebug) prout("Debug output ON");
else prout("Debug output OFF");
}
proutn("Cause selective damage? ");
else prout("Debug output OFF");
}
proutn("Cause selective damage? ");
#define min(x, y) ((x)<(y)?(x):(y))
#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))
#define max(x, y) ((x)>(y)?(x):(y))
#define PHASEFAC (2.0)
#define GALSIZE (8)
#define NINHAB (GALSIZE * GALSIZE / 2)
#define PHASEFAC (2.0)
#define GALSIZE (8)
#define NINHAB (GALSIZE * GALSIZE / 2)
iscraft, // =1 if craft on ship, -1 if removed from game
isatb, // =1 if super commander is attacking base
iscate, // super commander is here
iscraft, // =1 if craft on ship, -1 if removed from game
isatb, // =1 if super commander is attacking base
iscate, // super commander is here
-#ifdef DEBUG
- idebug, // debug mode
-#endif
iattak, // attack recursion elimination (was cracks[4])
icrystl, // dilithium crystals aboard
tourn, // tournament number
iattak, // attack recursion elimination (was cracks[4])
icrystl, // dilithium crystals aboard
tourn, // tournament number
extern double perdate;
extern double aaitem;
extern char citem[10];
extern double perdate;
extern double aaitem;
extern char citem[10];
+extern int seed;
+extern bool randready;
+extern bool idebug;
+extern FILE *logfp;
/* the Space Thingy's global state should *not* be saved! */
extern coord thing;
/* the Space Thingy's global state should *not* be saved! */
extern coord thing;