More int-to-boolean cleanup. Make the FDISTR event work.
[super-star-trek.git] / src / ai.c
index dbf65737a7e63d0e18ce5cfcc3911603969c52d2..9e6c31095e737b16d4cc08744b0a63b177af5b6d 100644 (file)
--- a/src/ai.c
+++ b/src/ai.c
@@ -130,7 +130,7 @@ static void movebaddy(coord com, int loccom, int ienm)
  */
 
        forces = game.kpower[loccom]+100.0*game.nenhere+400*(nbaddys-1);
-       if (game.shldup==0) forces += 1000; /* Good for enemy if shield is down! */
+       if (!game.shldup) forces += 1000; /* Good for enemy if shield is down! */
        if (game.damage[DPHASER] == 0.0 || game.damage[DPHOTON] == 0.0) {
            if (game.damage[DPHASER] != 0) /* phasers damaged */
                forces += 300.0;
@@ -154,12 +154,8 @@ static void movebaddy(coord com, int loccom, int ienm)
            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 */
@@ -170,11 +166,9 @@ static void movebaddy(coord com, int loccom, int ienm)
     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;
@@ -185,11 +179,8 @@ static void movebaddy(coord com, int loccom, int ienm)
     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;
@@ -234,14 +225,14 @@ static void movebaddy(coord com, int loccom, int ienm)
        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;
@@ -267,9 +258,7 @@ void movcom(void)
     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 */
@@ -302,7 +291,7 @@ void movcom(void)
     sortkl();
 }
 
-static int movescom(coord iq, int flag, int *ipage) 
+static bool movescom(coord iq, int flag, int *ipage) 
 {
     int i;
 
@@ -315,7 +304,7 @@ static int 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;
     }
-    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;
@@ -345,7 +334,7 @@ static int movescom(coord iq, int flag, int *ipage)
            game.state.plnets[i].crystals == 1) {
            /* destroy the planet */
            DESTROY(&game.state.plnets[i]);
-           game.state.galaxy[game.state.kscmdr.x][game.state.kscmdr.y].planet = NULL;
+           game.state.galaxy[game.state.kscmdr.x][game.state.kscmdr.y].planet = NOPLANET;
            if (game.damage[DRADIO] == 0.0 || game.condit == IHDOCKED) {
                if (*ipage==0) pause_game(1);
                *ipage = 1;
@@ -358,7 +347,7 @@ static int movescom(coord iq, int flag, int *ipage)
            break;
        }
     }
-    return 0; /* looks good! */
+    return false; /* looks good! */
 }
                        
 void scom(int *ipage)
@@ -368,9 +357,8 @@ 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) ||
@@ -497,7 +485,7 @@ void scom(int *ipage)
            /* 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);
@@ -512,19 +500,17 @@ void scom(int *ipage)
            prout(_("   reports that it is under attack from the Klingon Super-commander."));
            proutn(_("   It can survive until stardate %d.\""),
                   (int)scheduled(FSCDBAS));
-           if (game.resting==0) return;
+           if (!game.resting) return;
            prout(_("Mr. Spock-  \"Captain, shall we cancel the rest period?\""));
            if (ja()==0) return;
-           game.resting = 0;
+           game.resting = false;
            game.optime = 0.0; /* actually finished */
            return;
        }
     }
     /* 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))