]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - trek/events.c
robots: Use arc4random_uniform for better uniform distribution
[bsdgames-darwin.git] / trek / events.c
index e15ad251ead7964a8045f05bece6b37be62c5c33..62f23bcf9836e73d32a5a0e1d5717d5eb8a05cc0 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: events.c,v 1.10 2009/05/24 21:44:56 dholland Exp $     */
+/*     $NetBSD: events.c,v 1.11 2009/05/24 22:55:03 dholland Exp $     */
 
 /*
  * Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)events.c   8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: events.c,v 1.10 2009/05/24 21:44:56 dholland Exp $");
+__RCSID("$NetBSD: events.c,v 1.11 2009/05/24 22:55:03 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -152,7 +152,8 @@ events(int timewarp)
                                        for (iy = 0; iy < NQUADS; iy++) {
                                                q = &Quad[ix][iy];
                                                if (q->stars >= 0)
-                                                       if ((i -= q->klings) <= 0)
+                                                       if ((i -= q->klings)
+                                                           <= 0)
                                                                break;
                                        }
                                        if (i <= 0)
@@ -166,8 +167,11 @@ events(int timewarp)
                                /* nope, dump him in the new quadrant */
                                Ship.quadx = ix;
                                Ship.quady = iy;
-                               printf("\n%s caught in long range tractor beam\n", Ship.shipname);
-                               printf("*** Pulled to quadrant %d,%d\n", Ship.quadx, Ship.quady);
+                               printf("\n%s caught in long range tractor "
+                                      "beam\n",
+                                       Ship.shipname);
+                               printf("*** Pulled to quadrant %d,%d\n",
+                                       Ship.quadx, Ship.quady);
                                Ship.sectx = ranf(NSECTS);
                                Ship.secty = ranf(NSECTS);
                                initquad(0);
@@ -208,23 +212,33 @@ events(int timewarp)
                        }
                        e = ev;
                        if (i >= Now.bases) {
-                               /* not now; wait a while and see if some Klingons move in */
+                               /*
+                                * not now; wait a while and see if
+                                * some Klingons move in
+                                */
                                reschedule(e, 0.5 + 3.0 * franf());
                                break;
                        }
-                       /* schedule a new attack, and a destruction of the base */
+                       /*
+                        * schedule a new attack, and a destruction of
+                        * the base
+                        */
                        xresched(e, E_KATSB, 1);
                        e = xsched(E_KDESB, 1, ix, iy, 0);
 
                        /* report it if we can */
                        if (!damaged(SSRADIO)) {
-                               printf("\nUhura:  Captain, we have received a distress signal\n");
-                               printf("  from the starbase in quadrant %d,%d.\n",
+                               printf("\nUhura:  Captain, we have received a "
+                                      "distress signal\n");
+                               printf("  from the starbase in quadrant "
+                                      "%d,%d.\n",
                                        ix, iy);
                                restcancel++;
                        } else {
-                               /* SSRADIO out, make it so we can't see the distress call */
-                               /* but it's still there!!! */
+                               /*
+                                * SSRADIO out, make it so we can't see the
+                                * distress call but it's still there!!!
+                                */
                                e->evcode |= E_HIDDEN;
                        }
                        break;
@@ -232,8 +246,10 @@ events(int timewarp)
                  case E_KDESB:                 /* Klingon destroys starbase */
                        unschedule(e);
                        q = &Quad[e->x][e->y];
-                       /* if the base has mysteriously gone away, or if the Klingon
-                          got tired and went home, ignore this event */
+                       /*
+                        * if the base has mysteriously gone away, or if the
+                        * Klingon got tired and went home, ignore this event
+                        */
                        if (q->bases <=0 || q->klings <= 0)
                                break;
                        /* are we in the same quadrant? */
@@ -252,18 +268,23 @@ events(int timewarp)
                        /* if we already have too many, throw this one away */
                        if (Ship.distressed >= MAXDISTR)
                                break;
-                       /* try a whole bunch of times to find something suitable */
+                       /* try a bunch of times to find something suitable */
                        for (i = 0; i < 100; i++) {
                                ix = ranf(NQUADS);
                                iy = ranf(NQUADS);
                                q = &Quad[ix][iy];
-                               /* need a quadrant which is not the current one,
-                                  which has some stars which are inhabited and
-                                  not already under attack, which is not
-                                  supernova'ed, and which has some Klingons in it */
-                               if (!((ix == Ship.quadx && iy == Ship.quady) || q->stars < 0 ||
-                                   (q->qsystemname & Q_DISTRESSED) ||
-                                   (q->qsystemname & Q_SYSTEM) == 0 || q->klings <= 0))
+                               /*
+                                * need a quadrant which is not the current
+                                * one, which has some inhabited stars which
+                                * are not already under attack, which is not
+                                * supernova'ed, and which has some Klingons
+                                * in it
+                                */
+                               if (!((ix == Ship.quadx && iy == Ship.quady) ||
+                                     q->stars < 0 ||
+                                     (q->qsystemname & Q_DISTRESSED) ||
+                                     (q->qsystemname & Q_SYSTEM) == 0 ||
+                                     q->klings <= 0))
                                        break;
                        }
                        if (i >= 100)
@@ -277,7 +298,8 @@ events(int timewarp)
 
                        /* tell the captain about it if we can */
                        if (!damaged(SSRADIO)) {
-                               printf("\nUhura: Captain, starsystem %s in quadrant %d,%d is under attack\n",
+                               printf("\nUhura: Captain, starsystem %s in "
+                                      "quadrant %d,%d is under attack\n",
                                        Systemname[e->systemname], ix, iy);
                                restcancel++;
                        } else {
@@ -298,11 +320,13 @@ events(int timewarp)
                        }
 
                        /* play stork and schedule the first baby */
-                       e = schedule(E_REPRO, Param.eventdly[E_REPRO] * franf(), e->x, e->y, e->systemname);
+                       e = schedule(E_REPRO, Param.eventdly[E_REPRO] * franf(),
+                               e->x, e->y, e->systemname);
 
                        /* report the disaster if we can */
                        if (!damaged(SSRADIO)) {
-                               printf("\nUhura:  We've lost contact with starsystem %s\n",
+                               printf("\nUhura:  We've lost contact with "
+                                      "starsystem %s\n",
                                        Systemname[e->systemname]);
                                printf("  in quadrant %d,%d.\n",
                                        e->x, e->y);
@@ -335,8 +359,12 @@ events(int timewarp)
                                                if (j < 0 || j >= NQUADS)
                                                        continue;
                                                q = &Quad[i][j];
-                                               /* check for this quad ok (not full & no snova) */
-                                               if (q->klings >= MAXKLQUAD || q->stars < 0)
+                                               /*
+                                                * check for this quad ok (not
+                                                * full & no snova)
+                                                */
+                                               if (q->klings >= MAXKLQUAD ||
+                                                   q->stars < 0)
                                                        continue;
                                                break;
                                        }
@@ -361,7 +389,8 @@ events(int timewarp)
                                k->y = iy;
                                k->power = Param.klingpwr;
                                k->srndreq = 0;
-                               compkldist(Etc.klingon[0].dist == Etc.klingon[0].avgdist ? 0 : 1);
+                               compkldist(Etc.klingon[0].dist ==
+                                       Etc.klingon[0].avgdist ? 0 : 1);
                        }
 
                        /* recompute time left */
@@ -406,9 +435,12 @@ events(int timewarp)
                          case SINS:
                                if (Ship.cond == DOCKED)
                                        break;
-                               printf("Spock has tried to recalibrate your Space Internal Navigation System,\n");
-                               printf("  but he has no standard base to calibrate to.  Suggest you get\n");
-                               printf("  to a starbase immediately so that you can properly recalibrate.\n");
+                               printf("Spock has tried to recalibrate your "
+                                      "Space Internal Navigation System,\n");
+                               printf("  but he has no standard base to "
+                                      "calibrate to.  Suggest you get\n");
+                               printf("  to a starbase immediately so that "
+                                      "you can properly recalibrate.\n");
                                Ship.sinsbad = 1;
                                break;
 
@@ -422,7 +454,8 @@ events(int timewarp)
                        break;
                }
 
-               if (restcancel && Move.resting && getynpar("Spock: Shall we cancel our rest period"))
+               if (restcancel && Move.resting &&
+                   getynpar("Spock: Shall we cancel our rest period"))
                        Move.time = xdate - idate;
 
        }