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 */
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);
}
-#endif
/* 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++) {
-#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;
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 */
+
}
+ if (idebug)
+ prout("");
/* Put commander in place within same quadrant */
game.quad[com.x][com.y] = IHDOT;
game.quad[next.x][next.y] = ienm;
coord w;
int i;
-#ifdef DEBUG
- if (game.idebug) prout("MOVCOM");
-#endif
+ if (idebug) prout("== MOVCOM");
/* Figure out which Klingon is the commander (or Supercommander)
and do move */
sortkl();
}
-static int movescom(coord iq, int flag, int *ipage)
+static bool movescom(coord iq, int flag, int *ipage)
{
int i;
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;
break;
}
}
- return 0; /* looks good! */
+ return false; /* looks good! */
}
void scom(int *ipage)
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) ||
/* attack the base */
if (flag) return; /* no, don't attack base! */
game.iseenit = 0;
- game.isatb=1;
+ game.isatb = 1;
schedule(FSCDBAS, 1.0 +2.0*Rand());
if (is_scheduled(FCDBAS))
postpone(FSCDBAS, scheduled(FCDBAS)-game.state.date);
}
/* Check for intelligence report */
if (
-#ifdef DEBUG
- game.idebug==0 &&
-#endif
+ !idebug &&
(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;
-#ifdef DEBUG
- if (game.idebug) prout("ATTACK!");
-#endif
+ if (idebug) prout("=== ATTACK!");
if (game.ithere) movetho();
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);
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;
}
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);
}
if (num <=0) break;
}
-#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;
}
}
-#endif
}
if (nq.x != game.quadrant.y || nq.y != game.quadrant.y || game.justin != 0) {
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);
prout(_("You have smashed the Klingon invasion fleet and saved"));
prout(_("the Federation."));
- game.gamewon=1;
+ game.gamewon = true;
if (game.alive) {
double badpt;
badpt = 5.0*game.state.starkl + game.casual + 10.0*game.state.nplankl +
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? "));
(void)endwin();
putchar('\n');
}
+ if (logfp)
+ fclose(logfp);
}
void iostart(void)
} else {
fgets(line, max, stdin);
}
+ if (logfp)
+ fputs(line, logfp);
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;
-#ifdef DEBUG
- if (game.idebug &&game.warpfac==10 && twarp==0) {
+ if (idebug && game.warpfac==10 && twarp==0) {
blooey=0;
- proutn("Force time warp? ");
+ proutn("=== Force time warp? ");
if (ja()==1) twarp=1;
}
-#endif
if (blooey || twarp) {
/* If time warp or engine damage, check path */
/* If it is obstructed, don't do warp or damage */
void preport(void)
{
- int iknow = 0, i;
+ bool iknow = false;
+ int i;
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)
-#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]);
} else {
if (is_scheduled(FCDBAS))
proutn("Base in %i - %i attacked by C. Alive until %.1f", game.battle.x, game.battle.y, scheduled(FCDBAS));
- if (game.isatb == 1)
+ if (game.isatb)
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;
-#ifdef DEBUG
- game.idebug = 0;
-#endif
// 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;
-#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);
break;
}
-#ifdef DEBUG
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);
}
-#endif
}
} while (contflag);
// 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;
game.state.galaxy[ix][iy].klingons += klump;
} while (krem > 0);
// Position Klingon Commander Ships
-#ifdef DEBUG
+#ifdef ODEBUG
klumper = 1;
-#endif
+#endif /* ODEBUG */
for (i = 1; i <= game.incom; i++) {
do {
do { /* IF debugging, put commanders by bases, always! */
-#ifdef DEBUG
+#ifdef ODEBUG
if (game.idebug && klumper <= game.inbase) {
ix = game.state.baseq[klumper].x;
iy = game.state.baseq[klumper].y;
klumper++;
}
else
-#endif
+#endif /* ODEBUG */
iran(GALSIZE, &ix, &iy);
}
while ((!game.state.galaxy[ix][iy].klingons && Rand() < 0.75)||
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;
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;
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];
+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",
if (game.ididit) hitme = true;
break;
case DEBUGCMD: // What do we want for debug???
-#ifdef DEBUG
debugme();
-#endif
break;
case MAYDAY: // Call for help
mayday();
break;
case QUIT:
game.alldone = 1; // quit the game
-#ifdef DEBUG
- if (game.idebug) score();
-#endif
break;
case HELP:
helpme(); // get help
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.alldone) break;
}
+ if (idebug) prout("=== Ending");
}
}
for(;;) { /* Play a game */
setwnd(fullscreen_window);
-#ifdef DEBUG
- prout("INITIAL OPTIONS: %0lx", game.options);
-#endif /* DEBUG */
clrscr();
prelim();
setup(line[0] == '\0');
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)
}
-#ifdef DEBUG
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? ");
}
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? ");
atover(1);
}
}
-#endif
#define min(x, y) ((x)<(y)?(x):(y))
#define max(x, y) ((x)>(y)?(x):(y))
-// #define DEBUG
-
#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
-#ifdef DEBUG
- idebug, // debug mode
-#endif
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 int seed;
+extern bool randready;
+extern bool idebug;
+extern FILE *logfp;
/* the Space Thingy's global state should *not* be saved! */
extern coord thing;