New debug-mode support.
[super-star-trek.git] / src / setup.c
index 3e6718f4620b1bc0339e0fa205f40c504e2e6a8d..7b17fbcd9c0745556310ee8ff3ce120963257ab0 100644 (file)
@@ -19,7 +19,7 @@ void prelim(void)
 #endif /* __HISTORICAL__ */
 }
 
-void freeze(int boss) 
+void freeze(bool boss) 
 {
     FILE *fp;
     int key;
@@ -195,9 +195,6 @@ void setup(int needprompt)
 {
     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
@@ -269,26 +266,24 @@ void setup(int needprompt)
        }
     // Locate star bases in galaxy
     for (i = 1; i <= game.inbase; i++) {
-       int contflag;
+       bool contflag;
        do {
            do iran(GALSIZE, &ix, &iy);
            while (game.state.galaxy[ix][iy].starbase);
-           contflag = FALSE;
+           contflag = false;
            for (j = i-1; j > 0; j--) {
                /* Improved placement algorithm to spread out bases */
                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
+                   contflag = true;
+                   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);
                        
@@ -300,7 +295,8 @@ void setup(int needprompt)
     // 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;
@@ -312,20 +308,20 @@ void setup(int needprompt)
        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)||
@@ -423,9 +419,9 @@ void setup(int needprompt)
     if (game.neutz) attack(0); // bad luck to start in a Romulan Neutral Zone
 }
 
-int choose(int needprompt) 
+bool choose(bool needprompt) 
 {
-    while (TRUE) {
+    for(;;) {
        game.tourn = 0;
        game.thawed = 0;
        game.skill = SKILL_NONE;
@@ -454,7 +450,7 @@ int choose(int needprompt)
            if (!game.alldone) game.thawed = 1; // No plaque if not finished
            report();
            waitfor();
-           return TRUE;
+           return true;
        }
        if (isit("regular")) break;
        proutn("What is \"");
@@ -508,9 +504,11 @@ int choose(int needprompt)
            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;
@@ -531,7 +529,7 @@ int choose(int needprompt)
     if (game.inkling > 50) {
        game.inbase = (game.state.rembase += 1);
     }
-    return FALSE;
+    return false;
 }
 
 void dropin(int iquad, coord *w) 
@@ -687,9 +685,6 @@ void newqad(int shutup)
        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;
@@ -730,17 +725,18 @@ void newqad(int shutup)
 void sortkl(void) 
 {
     double t;
-    int sw, j, k;
+    int j, k;
+    bool sw;
 
     // The author liked bubble sort. So we will use it. :-(
 
     if (game.nenhere-iqhere-game.ithere < 2) return;
 
     do {
-       sw = FALSE;
+       sw = false;
        for (j = 1; j < game.nenhere; j++)
            if (game.kdist[j] > game.kdist[j+1]) {
-               sw = TRUE;
+               sw = true;
                t = game.kdist[j];
                game.kdist[j] = game.kdist[j+1];
                game.kdist[j+1] = t;