]> git.pond.sub.org Git - empserver/commitdiff
Instead of patching Make.sysdefs, introduce emp_{,s}random() and patch
authorMarc Olzheim <marcolz@stack.nl>
Sun, 20 Jun 2004 15:30:41 +0000 (15:30 +0000)
committerMarc Olzheim <marcolz@stack.nl>
Sun, 20 Jun 2004 15:30:41 +0000 (15:30 +0000)
all files to use it.  Output from the nightly build machines should
now be the same for the different platforms.

src/scripts/nightly/patches/All/prng.patch

index f07b6e70afa64725c7df680787ef650038ec7123..4bc4e080f06d9f0637b03daecbdc14be6897c0c8 100644 (file)
-Index: empserver/Make.sysdefs
---- empserver/Make.sysdefs     Sun Mar 21 16:44:42 2004
-+++ empserver/Make.sysdefs     Sat Jun 19 15:45:43 2004
-@@ -158,3 +158,5 @@
- VAXULTCFLAGS = -O -DNOSTRDUP -DPOSIXSIGNALS
- VAXULTLFLAGS =
- VAXULTMASTER = GLOBALCFLAGS="$(VAXULTCFLAGS)" GLOBALLFLAGS="$(VAXULTLFLAGS)"
-+
-+GLOBALCFLAGS += -DRANDOM=lrand48 -DSRANDOM=srand48 -DNIGHTLY
+Index: empserver/include/damage.h
+--- empserver/include/damage.h 23 Aug 2003 12:19:27 -0000      1.1.1.1
++++ empserver/include/damage.h 20 Jun 2004 15:14:58 -0000
+@@ -39,10 +39,10 @@
+ #define DPERCENT_DAMAGE(x) ((double)(100.0 * (x) / ((x) + 100.0)))
+ #define DMINE_HITCHANCE(x) ((double) ( (x) / ((x)+20.0) ) )
+ #define DMINE_LHITCHANCE(x) ((double) ( (x) / ((x)+35.0) ) )
+-#define MINE_DAMAGE() (22 + random()%21)
+-#define MINE_LDAMAGE() (10 + random()%11)
++#define MINE_DAMAGE() (22 + emp_random()%21)
++#define MINE_LDAMAGE() (10 + emp_random()%11)
+ #define DTORP_HITCHANCE(range, vis) ((double)(0.9/((range)+1)+(((vis)<6)?(5-(vis))*0.03:0)))
+-#define TORP_DAMAGE() (torpedo_damage + (random() % torpedo_damage) + \
+-                     (random() % torpedo_damage))
++#define TORP_DAMAGE() (torpedo_damage + (emp_random() % torpedo_damage) + \
++                     (emp_random() % torpedo_damage))
+ #endif /* _DAMAGE_H_ */
+Index: empserver/include/prototypes.h
+--- empserver/include/prototypes.h     16 May 2004 14:19:38 -0000      1.45
++++ empserver/include/prototypes.h     20 Jun 2004 15:14:59 -0000
+@@ -227,6 +227,9 @@
+ #ifdef NOSTRDUP
+ extern char *strdup(char *x);
+ #endif
++/* chance.c */
++extern void emp_srandom(unsigned int);
++extern long emp_random(void);
+ /* more in misc.h */
+ /*
+Index: empserver/src/lib/commands/anti.c
+--- empserver/src/lib/commands/anti.c  4 Mar 2004 13:49:25 -0000       1.6
++++ empserver/src/lib/commands/anti.c  20 Jun 2004 15:15:00 -0000
+@@ -132,7 +132,7 @@
+                   sect.sct_mobil = 0;
+               }
+               sect.sct_loyal = sect.sct_loyal * 0.5;
+-              n_cheleft = (random() % 4);
++              n_cheleft = (emp_random() % 4);
+               /* 75% chance some che will get left */
+               if (n_cheleft) {
+                   /* Ok, now leave anywhere from 16% to 25% of the che */
+Index: empserver/src/lib/commands/laun.c
+--- empserver/src/lib/commands/laun.c  28 Feb 2004 17:44:02 -0000      1.3
++++ empserver/src/lib/commands/laun.c  20 Jun 2004 15:15:01 -0000
+@@ -427,7 +427,7 @@
+     }
+     i = pp->pln_tech + pp->pln_effic;
+     if (chance(1.0 - (i / (i + 50.0)))) {
+-      dir = (random() % 6) + 1;
++      dir = (emp_random() % 6) + 1;
+       sx += diroff[dir][0];
+       sy += diroff[dir][1];
+       pr("Your trajectory was a little off.\n");
+Index: empserver/src/lib/commands/mfir.c
+--- empserver/src/lib/commands/mfir.c  10 May 2004 19:48:42 -0000      1.13
++++ empserver/src/lib/commands/mfir.c  20 Jun 2004 15:15:02 -0000
+@@ -567,18 +567,12 @@
+           pr("Kaboom!!!\n");
+           prb = (double)(range2 ? (trange / range2) : 1.0);
+           prb *= prb;
+-#if !defined(_WIN32)
+-          srandom(random());
+-#else
+-          (void)time(&now);
+-          (void)srand(now);
+-#endif
+           if (chance(prb)) {
+               pr("Wind deflects shell%s.\n", splur(shots));
+ /*                    dam = (int)((double)dam / 2.0);*/
+               dam =
+                   (int)((double)dam *
+-                        (double)((double)(90 - (random() % 11)) /
++                        (double)((double)(90 - (emp_random() % 11)) /
+                                  100.0));
+               if (dam < 0)
+                   dam = 0;
+Index: empserver/src/lib/commands/new.c
+--- empserver/src/lib/commands/new.c   5 Mar 2004 12:05:33 -0000       1.13
++++ empserver/src/lib/commands/new.c   20 Jun 2004 15:15:02 -0000
+@@ -106,16 +106,10 @@
+           return RET_SYN;
+       }
+     } else {
+-      (void)time(&now);
+-#if !defined(_WIN32)
+-      srandom(now);
+-#else
+-      srand(now);
+-#endif
+       for (i = 0; i < 300 && !player->aborted; i++) {
+           /* Both x and y should be either odd or even */
+-          x = (random() % WORLD_X) - (WORLD_X / 2);
+-          y = (((random() % WORLD_Y) - (WORLD_Y / 2)) & ~1) | (x & 1);
++          x = (emp_random() % WORLD_X) - (WORLD_X / 2);
++          y = (((emp_random() % WORLD_Y) - (WORLD_Y / 2)) & ~1) | (x & 1);
+           /*
+            * If either of the two potential
+            * sanctuary sectors are already
+Index: empserver/src/lib/commands/news.c
+--- empserver/src/lib/commands/news.c  20 Feb 2004 20:34:42 -0000      1.5
++++ empserver/src/lib/commands/news.c  20 Jun 2004 15:15:02 -0000
+@@ -182,7 +182,7 @@
+     /*
+      * vary the order of the printing of "%d times "
+      */
+-    if ((random() & 3) == 0 && np->nws_ntm > 1) {
++    if ((emp_random() & 3) == 0 && np->nws_ntm > 1) {
+       sprintf(cp, "%s times ", ptr);
+       cp += strlen(cp);
+       np->nws_ntm = 1;
+@@ -192,7 +192,7 @@
+     *cp++ = ' ';
+     if (np->nws_vrb < 1 || np->nws_vrb > N_MAX_VERB)
+       np->nws_vrb = 0;
+-    sprintf(cp, rpt[(int)np->nws_vrb].r_newstory[random() % NUM_RPTS],
++    sprintf(cp, rpt[(int)np->nws_vrb].r_newstory[emp_random() % NUM_RPTS],
+           cname(np->nws_vno));
+     cp += strlen(cp);
+     if (np->nws_ntm != 1) {
+Index: empserver/src/lib/commands/sabo.c
+--- empserver/src/lib/commands/sabo.c  5 Mar 2004 10:38:58 -0000       1.7
++++ empserver/src/lib/commands/sabo.c  20 Jun 2004 15:15:03 -0000
+@@ -87,10 +87,10 @@
+       dam = landgun(3 * land.lnd_effic, 7);
+       if (sect.sct_item[I_SHELL] > 20)
+           dam += seagun(land.lnd_effic,
+-                        random() % (sect.sct_item[I_SHELL] / 10));
++                        emp_random() % (sect.sct_item[I_SHELL] / 10));
+       if (sect.sct_item[I_PETROL] > 100)
+           dam += seagun(land.lnd_effic,
+-                        random() % (sect.sct_item[I_PETROL] / 50));
++                        emp_random() % (sect.sct_item[I_PETROL] / 50));
+       pr("Explosion in %s causes %d damage.\n",
+          xyas(land.lnd_x, land.lnd_y, land.lnd_own), dam);
+Index: empserver/src/lib/common/damage.c
+--- empserver/src/lib/common/damage.c  6 Mar 2004 07:16:45 -0000       1.5
++++ empserver/src/lib/common/damage.c  20 Jun 2004 15:15:04 -0000
+@@ -179,7 +179,7 @@
+       return 0;
+     tmp = amt * pct;
+     lost = tmp / 100;
+-    if ((random() % 100) < (tmp % 100))
++    if ((emp_random() % 100) < (tmp % 100))
+       lost++;
+     return amt - lost;
+ }
 Index: empserver/src/lib/gen/chance.c
---- empserver/src/lib/gen/chance.c     Tue Sep  2 22:48:48 2003
-+++ empserver/src/lib/gen/chance.c     Sun Jun 20 15:51:09 2004
-@@ -33,21 +33,17 @@
+--- empserver/src/lib/gen/chance.c     2 Sep 2003 20:48:48 -0000       1.2
++++ empserver/src/lib/gen/chance.c     20 Jun 2004 15:15:05 -0000
+@@ -33,23 +33,27 @@
  
  #include "gen.h"
  
 -#ifdef hpux
-+#ifdef NIGHTLY
++#ifndef       RANDOM
++#ifdef        NOSVIDPRNG
++#define       RANDOM  random
++#define       SRANDOM srandom
++#else /* ! NOSVIDPRNG */
++#define       RANDOM  lrand48
++#define       SRANDOM srand48
++#endif        /* ! NOSVIDPRNG */
++#endif        /* RANDOM */
++
  void
- srandom(unsigned int n)
+-srandom(unsigned int n)
++emp_srandom(unsigned int n)
  {
 -    extern void srand48();
 -
 -    srand48(n);
-+    SRANDOM(0);
++    SRANDOM(n);
  }
  
  long
- random(void)
+-random(void)
++emp_random(void)
  {
 -    extern long lrand48();
 -
 -    return (lrand48());               /* 5/28/91 by bailey@mcs.kent.edu */
 +    return (RANDOM());                /* 5/28/91 by bailey@mcs.kent.edu */
  }
+-#endif
+ int
+ chance(double d)
+Index: empserver/src/lib/subs/attsub.c
+--- empserver/src/lib/subs/attsub.c    5 Mar 2004 13:14:28 -0000       1.17
++++ empserver/src/lib/subs/attsub.c    20 Jun 2004 15:15:06 -0000
+@@ -1927,12 +1927,12 @@
+      * recalculate the odds every 8-50 casualties, not every cacsualty,
+      * since a single dead guy normally wouldn't cause a commander to
+      * rethink his strategies, but 50 dead guys might. */
+-    odds = odds + (double)((double)((random() % 11) - 5) / 100.0);
++    odds = odds + (double)((double)((emp_random() % 11) - 5) / 100.0);
+     if (odds < 0.0)
+       odds = 0.1;
+     if (odds > 1.0)
+       odds = 1.0;
+-    recalctime = 8 + (random() % 43);
++    recalctime = 8 + (emp_random() % 43);
+     while (!success && ototal) {
+       if (chance(odds)) {
+           pr("!");
+@@ -1948,9 +1948,9 @@
+       if (((a_cas + d_cas) % 70) == 69)
+           pr("\n");
+       if (recalctime-- <= 0) {
+-          recalctime = 8 + (random() % 43);
++          recalctime = 8 + (emp_random() % 43);
+           odds = att_calcodds(ototal, dtotal);
+-          odds = odds + (double)((double)((random() % 11) - 5) / 100.0);
++          odds = odds + (double)((double)((emp_random() % 11) - 5) / 100.0);
+           if (odds < 0.0)
+               odds = 0.1;
+           if (odds > 1.0)
+Index: empserver/src/lib/subs/landgun.c
+--- empserver/src/lib/subs/landgun.c   2 Sep 2003 20:48:48 -0000       1.2
++++ empserver/src/lib/subs/landgun.c   20 Jun 2004 15:15:07 -0000
+@@ -43,7 +43,7 @@
+     double d;
+     double g = (double)min(guns, 7);
+-    d = ((double)(random() % 30) + 20.0) * ((double)g / 7.0);
++    d = ((double)(emp_random() % 30) + 20.0) * ((double)g / 7.0);
+     d *= ((double)effic);
+     d /= 100.0;
+     return d;
+@@ -56,7 +56,7 @@
+     d = 0.0;
+     while (guns--)
+-      d += 10.0 + (double)(random() % 6);
++      d += 10.0 + (double)(emp_random() % 6);
+     d *= ((double)effic) * 0.01;
+     return d;
+ }
+@@ -68,7 +68,7 @@
+     shots = min(shots, guns);
+     while (shots-- > 0)
+-      d += 5.0 + (double)(random() % 6);
++      d += 5.0 + (double)(emp_random() % 6);
+     d *= ((double)effic) * 0.01;
+     if (shells < ammo && ammo != 0)
+       d *= (double)((double)shells / (double)ammo);
+Index: empserver/src/lib/subs/shpsub.c
+--- empserver/src/lib/subs/shpsub.c    16 May 2004 14:19:36 -0000      1.13
++++ empserver/src/lib/subs/shpsub.c    20 Jun 2004 15:15:08 -0000
+@@ -768,7 +768,7 @@
+     nreport(sp->shp_own, N_HIT_MINE, 0, 1);
+-    m = 22.0 + (double)(random() % 21);
++    m = 22.0 + (double)(emp_random() % 21);
+     if (mcp->m_flags & M_SWEEP)
+       m /= 2.0;
+Index: empserver/src/lib/subs/takeover.c
+--- empserver/src/lib/subs/takeover.c  4 Mar 2004 13:49:25 -0000       1.10
++++ empserver/src/lib/subs/takeover.c  20 Jun 2004 15:15:08 -0000
+@@ -92,7 +92,7 @@
+           if (!(chance(LND_SPY_DETECT_CHANCE(lp->lnd_effic))))
+               continue;
+       }
+-      n = lp->lnd_effic - (30 + (random() % 100));
++      n = lp->lnd_effic - (30 + (emp_random() % 100));
+       if (n < 0)
+           n = 0;
+       lp->lnd_effic = n;
+@@ -121,7 +121,7 @@
+      * how spunky are these guys?
+      * n: random number from -25:75 + (50 - loyalty)
+      */
+-    n = (50 - sp->sct_loyal) + ((random() % 100) - 25);
++    n = (50 - sp->sct_loyal) + ((emp_random() % 100) - 25);
+     che_count = 0;
+     if (n > 0 && sp->sct_own == sp->sct_oldown) {
+       che_count = (civ * n / 3000) + 5;
+@@ -179,7 +179,7 @@
+      * XXX If this was done right, planes could escape,
+      * flying to a nearby friendly airport.
+      */
+-    n = pp->pln_effic - (30 + (random() % 100));
++    n = pp->pln_effic - (30 + (emp_random() % 100));
+     if (n < 0)
+       n = 0;
+     pp->pln_effic = n;
+Index: empserver/src/lib/update/human.c
+--- empserver/src/lib/update/human.c   14 May 2004 20:21:46 -0000      1.11
++++ empserver/src/lib/update/human.c   20 Jun 2004 15:15:09 -0000
+@@ -124,7 +124,7 @@
+           sctwork = 0;
+       } else {
+           if (sp->sct_work < 100)
+-              sctwork = sp->sct_work + 8 + (random() % 15);
++              sctwork = sp->sct_work + 8 + (emp_random() % 15);
+           if (sctwork > 100)
+               sctwork = 100;
+           if (!player->simulation)
+@@ -321,5 +321,5 @@
+ starvation(struct sctstr *sp)
+ {
+     sp->sct_work = 0;
+-    sp->sct_loyal += (random() % 8) + 2;
++    sp->sct_loyal += (emp_random() % 8) + 2;
+ }
+Index: empserver/src/lib/update/plague.c
+--- empserver/src/lib/update/plague.c  11 Mar 2004 18:10:25 -0000      1.8
++++ empserver/src/lib/update/plague.c  20 Jun 2004 15:15:09 -0000
+@@ -191,7 +191,7 @@
+     }
+     if (*ptime <= 0) {
+       *pstage -= 1;
+-      *ptime = (etus / 2) + (random() % etus);
++      *ptime = (etus / 2) + (emp_random() % etus);
+     }
+     return stage;
+ }
+Index: empserver/src/lib/update/populace.c
+--- empserver/src/lib/update/populace.c        10 Mar 2004 17:59:37 -0000      1.3
++++ empserver/src/lib/update/populace.c        20 Jun 2004 15:15:09 -0000
+@@ -89,7 +89,7 @@
+       n = roundavg(etu * 0.125);
+       if (n == 0)
+           n = 1;
+-      n = sp->sct_loyal + (random() % n) + 1;
++      n = sp->sct_loyal + (emp_random() % n) + 1;
+       if (n > 127)
+           n = 127;
+       sp->sct_loyal = n;
+@@ -97,7 +97,7 @@
+     if (sp->sct_loyal > 65 && mil < civ / 20) {
+       int work_red;
+-      work_red = sp->sct_loyal - (50 + (random() % 15));
++      work_red = sp->sct_loyal - (50 + (emp_random() % 15));
+       n = sp->sct_work - work_red;
+       if (n < 0)
+           n = 0;
+Index: empserver/src/lib/update/revolt.c
+--- empserver/src/lib/update/revolt.c  5 Mar 2004 10:38:57 -0000       1.10
++++ empserver/src/lib/update/revolt.c  20 Jun 2004 15:15:09 -0000
+@@ -72,7 +72,7 @@
+     che_uw = 0;
+     che_civ = 0;
+     /* che due to civilian unrest */
+-    n = 10 - (random() % 20);
++    n = 10 - (emp_random() % 20);
+     che_civ = 3 + (civ * n / 500);
+     if (che_civ < 0)
+       che_civ = 0;
+@@ -83,7 +83,7 @@
+     che += che_civ;
+     if (che < CHE_MAX) {
+       /* che due to uw unrest */
+-      n = 10 + (random() % 30);
++      n = 10 + (emp_random() % 30);
+       che_uw = 5 + (uw * n / 500);
+       if (che_uw > uw)
+           che_uw = uw;
+@@ -254,7 +254,7 @@
+       }
+       if (mil > 0) {
+           /* military won.  */
+-          n = sp->sct_loyal - (random() % 15);
++          n = sp->sct_loyal - (emp_random() % 15);
+           if (n < 0)
+               n = 0;
+           sp->sct_loyal = n;
+@@ -273,7 +273,7 @@
+        * Note this disrupts work in the sector.
+        */
+       n = 0;
+-      n = (random() % 10) + (random() % che);
++      n = (emp_random() % 10) + (emp_random() % che);
+       if (n > 100)
+           n = 100;
+       tmp = sp->sct_work - n;
+@@ -359,14 +359,14 @@
+       /* loyalty drops during recruitment efforts */
+       n = sp->sct_loyal;
+       if (n < 30)
+-          n += (random() % 5) + 1;
++          n += (emp_random() % 5) + 1;
+       else if (n < 70)
+-          n += (random() % 10) + 4;
++          n += (emp_random() % 10) + 4;
+       if (n > 127)
+           n = 127;
+       sp->sct_loyal = n;
+       if (sp->sct_oldown != sp->sct_own || n > 100) {
+-          n = civ * (random() % 3) / 200;
++          n = civ * (emp_random() % 3) / 200;
+           n /= hap_fact(tnat, getnatp(sp->sct_oldown));
+           if (n + che > CHE_MAX)
+               n = CHE_MAX - che;
+@@ -374,7 +374,7 @@
+           civ -= n;
+           sp->sct_item[I_CIVIL] = civ;
+       }
+-      n = uw * (random() % 3) / 200;
++      n = uw * (emp_random() % 3) / 200;
+       if (n + che > CHE_MAX)
+           n = CHE_MAX - che;
+       che += n;
+@@ -407,7 +407,7 @@
+           val = roundintby(val, 10);
+           /* inject a modicum of indeterminism; also
+            * avoids che preferring certain directions */
+-          val += random() % 10 - 5;
++          val += emp_random() % 10 - 5;
+           if (val >= min_mil)
+               continue;
+           nicest_sp = nsp;
+Index: empserver/src/util/fairland.c
+--- empserver/src/util/fairland.c      23 Mar 2004 15:20:17 -0000      1.10
++++ empserver/src/util/fairland.c      20 Jun 2004 15:15:10 -0000
+@@ -124,10 +124,10 @@
+ #define max(a,b) (a>b?a:b)
+ #endif
+ #ifndef SRANDOM
+-#define SRANDOM srandom
++#define SRANDOM srand48
+ #endif
+ #ifndef RANDOM
+-#define RANDOM random
++#define RANDOM lrand48
  #endif
+ #define rnd(x) (RANDOM() % (x))