]> git.pond.sub.org Git - empserver/blob - src/scripts/nightly/patches/All/prng.patch
Update patch offsets. No functional changes.
[empserver] / src / scripts / nightly / patches / All / prng.patch
1 Index: empserver/include/damage.h
2 --- empserver/include/damage.h  23 Aug 2003 12:19:27 -0000      1.1.1.1
3 +++ empserver/include/damage.h  20 Jun 2004 15:14:58 -0000
4 @@ -39,10 +39,10 @@
5  #define DPERCENT_DAMAGE(x) ((double)(100.0 * (x) / ((x) + 100.0)))
6  #define DMINE_HITCHANCE(x) ((double) ( (x) / ((x)+20.0) ) )
7  #define DMINE_LHITCHANCE(x) ((double) ( (x) / ((x)+35.0) ) )
8 -#define MINE_DAMAGE() (22 + random()%21)
9 -#define MINE_LDAMAGE() (10 + random()%11)
10 +#define MINE_DAMAGE() (22 + emp_random()%21)
11 +#define MINE_LDAMAGE() (10 + emp_random()%11)
12  #define DTORP_HITCHANCE(range, vis) ((double)(0.9/((range)+1)+(((vis)<6)?(5-(vis))*0.03:0)))
13 -#define TORP_DAMAGE() (torpedo_damage + (random() % torpedo_damage) + \
14 -                      (random() % torpedo_damage))
15 +#define TORP_DAMAGE() (torpedo_damage + (emp_random() % torpedo_damage) + \
16 +                      (emp_random() % torpedo_damage))
17  
18  #endif /* _DAMAGE_H_ */
19 Index: empserver/include/prototypes.h
20 --- empserver/include/prototypes.h      16 May 2004 14:19:38 -0000      1.45
21 +++ empserver/include/prototypes.h      20 Jun 2004 15:14:59 -0000
22 @@ -219,6 +219,9 @@
23  #ifdef NOSTRDUP
24  extern char *strdup(char *x);
25  #endif
26 +/* chance.c */
27 +extern void emp_srandom(unsigned int);
28 +extern long emp_random(void);
29  /* more in misc.h */
30  
31  /*
32 Index: empserver/src/lib/commands/anti.c
33 --- empserver/src/lib/commands/anti.c   4 Mar 2004 13:49:25 -0000       1.6
34 +++ empserver/src/lib/commands/anti.c   20 Jun 2004 15:15:00 -0000
35 @@ -131,7 +131,7 @@
36                     sect.sct_mobil = 0;
37                 }
38                 sect.sct_loyal = sect.sct_loyal * 0.5;
39 -               n_cheleft = (random() % 4);
40 +               n_cheleft = (emp_random() % 4);
41                 /* 75% chance some che will get left */
42                 if (n_cheleft) {
43                     /* Ok, now leave anywhere from 16% to 25% of the che */
44 Index: empserver/src/lib/commands/laun.c
45 --- empserver/src/lib/commands/laun.c   28 Feb 2004 17:44:02 -0000      1.3
46 +++ empserver/src/lib/commands/laun.c   20 Jun 2004 15:15:01 -0000
47 @@ -426,7 +426,7 @@
48      }
49      i = pp->pln_tech + pp->pln_effic;
50      if (chance(1.0 - (i / (i + 50.0)))) {
51 -       dir = (random() % 6) + 1;
52 +       dir = (emp_random() % 6) + 1;
53         sx += diroff[dir][0];
54         sy += diroff[dir][1];
55         pr("Your trajectory was a little off.\n");
56 Index: empserver/src/lib/commands/mfir.c
57 --- empserver/src/lib/commands/mfir.c   10 May 2004 19:48:42 -0000      1.13
58 +++ empserver/src/lib/commands/mfir.c   20 Jun 2004 15:15:02 -0000
59 @@ -560,18 +560,12 @@
60             pr("Kaboom!!!\n");
61             prb = (double)(range2 ? (trange / range2) : 1.0);
62             prb *= prb;
63 -#if !defined(_WIN32)
64 -           srandom(random());
65 -#else
66 -           (void)time(&now);
67 -           (void)srand(now);
68 -#endif
69             if (chance(prb)) {
70                 pr("Wind deflects shell%s.\n", splur(shots));
71  /*                     dam = (int)((double)dam / 2.0);*/
72                 dam =
73                     (int)((double)dam *
74 -                         (double)((double)(90 - (random() % 11)) /
75 +                         (double)((double)(90 - (emp_random() % 11)) /
76                                    100.0));
77                 if (dam < 0)
78                     dam = 0;
79 Index: empserver/src/lib/commands/new.c
80 --- empserver/src/lib/commands/new.c    5 Mar 2004 12:05:33 -0000       1.13
81 +++ empserver/src/lib/commands/new.c    20 Jun 2004 15:15:02 -0000
82 @@ -105,16 +105,10 @@
83             return RET_SYN;
84         }
85      } else {
86 -       (void)time(&now);
87 -#if !defined(_WIN32)
88 -       srandom(now);
89 -#else
90 -       srand(now);
91 -#endif
92         for (i = 0; i < 300 && !player->aborted; i++) {
93             /* Both x and y should be either odd or even */
94 -           x = (random() % WORLD_X) - (WORLD_X / 2);
95 -           y = (((random() % WORLD_Y) - (WORLD_Y / 2)) & ~1) | (x & 1);
96 +           x = (emp_random() % WORLD_X) - (WORLD_X / 2);
97 +           y = (((emp_random() % WORLD_Y) - (WORLD_Y / 2)) & ~1) | (x & 1);
98             /*
99              * If either of the two potential
100              * sanctuary sectors are already
101 Index: empserver/src/lib/commands/news.c
102 --- empserver/src/lib/commands/news.c   20 Feb 2004 20:34:42 -0000      1.5
103 +++ empserver/src/lib/commands/news.c   20 Jun 2004 15:15:02 -0000
104 @@ -187,7 +187,7 @@
105      /*
106       * vary the order of the printing of "%d times "
107       */
108 -    if ((random() & 3) == 0 && np->nws_ntm > 1) {
109 +    if ((emp_random() & 3) == 0 && np->nws_ntm > 1) {
110         sprintf(cp, "%s times ", ptr);
111         cp += strlen(cp);
112         np->nws_ntm = 1;
113 @@ -197,7 +197,7 @@
114      *cp++ = ' ';
115      if (np->nws_vrb < 1 || np->nws_vrb > N_MAX_VERB)
116         np->nws_vrb = 0;
117 -    sprintf(cp, rpt[(int)np->nws_vrb].r_newstory[random() % NUM_RPTS],
118 +    sprintf(cp, rpt[(int)np->nws_vrb].r_newstory[emp_random() % NUM_RPTS],
119             cname(np->nws_vno));
120      cp += strlen(cp);
121      if (np->nws_ntm != 1) {
122 Index: empserver/src/lib/commands/sabo.c
123 --- empserver/src/lib/commands/sabo.c   5 Mar 2004 10:38:58 -0000       1.7
124 +++ empserver/src/lib/commands/sabo.c   20 Jun 2004 15:15:03 -0000
125 @@ -86,10 +86,10 @@
126         dam = landgun(3 * land.lnd_effic, 7);
127         if (sect.sct_item[I_SHELL] > 20)
128             dam += seagun(land.lnd_effic,
129 -                         random() % (sect.sct_item[I_SHELL] / 10));
130 +                         emp_random() % (sect.sct_item[I_SHELL] / 10));
131         if (sect.sct_item[I_PETROL] > 100)
132             dam += seagun(land.lnd_effic,
133 -                         random() % (sect.sct_item[I_PETROL] / 50));
134 +                         emp_random() % (sect.sct_item[I_PETROL] / 50));
135  
136         pr("Explosion in %s causes %d damage.\n",
137            xyas(land.lnd_x, land.lnd_y, land.lnd_own), dam);
138 Index: empserver/src/lib/common/damage.c
139 --- empserver/src/lib/common/damage.c   6 Mar 2004 07:16:45 -0000       1.5
140 +++ empserver/src/lib/common/damage.c   20 Jun 2004 15:15:04 -0000
141 @@ -179,7 +179,7 @@
142         return 0;
143      tmp = amt * pct;
144      lost = tmp / 100;
145 -    if ((random() % 100) < (tmp % 100))
146 +    if ((emp_random() % 100) < (tmp % 100))
147         lost++;
148      return amt - lost;
149  }
150 Index: empserver/src/lib/subs/attsub.c
151 --- empserver/src/lib/subs/attsub.c     5 Mar 2004 13:14:28 -0000       1.17
152 +++ empserver/src/lib/subs/attsub.c     20 Jun 2004 15:15:06 -0000
153 @@ -1925,12 +1925,12 @@
154       * recalculate the odds every 8-50 casualties, not every cacsualty,
155       * since a single dead guy normally wouldn't cause a commander to
156       * rethink his strategies, but 50 dead guys might. */
157 -    odds = odds + (double)((double)((random() % 11) - 5) / 100.0);
158 +    odds = odds + (double)((double)((emp_random() % 11) - 5) / 100.0);
159      if (odds < 0.0)
160         odds = 0.1;
161      if (odds > 1.0)
162         odds = 1.0;
163 -    recalctime = 8 + (random() % 43);
164 +    recalctime = 8 + (emp_random() % 43);
165      while (!success && ototal) {
166         if (chance(odds)) {
167             pr("!");
168 @@ -1946,9 +1946,9 @@
169         if (((a_cas + d_cas) % 70) == 69)
170             pr("\n");
171         if (recalctime-- <= 0) {
172 -           recalctime = 8 + (random() % 43);
173 +           recalctime = 8 + (emp_random() % 43);
174             odds = att_calcodds(ototal, dtotal);
175 -           odds = odds + (double)((double)((random() % 11) - 5) / 100.0);
176 +           odds = odds + (double)((double)((emp_random() % 11) - 5) / 100.0);
177             if (odds < 0.0)
178                 odds = 0.1;
179             if (odds > 1.0)
180 Index: empserver/src/lib/subs/landgun.c
181 --- empserver/src/lib/subs/landgun.c    2 Sep 2003 20:48:48 -0000       1.2
182 +++ empserver/src/lib/subs/landgun.c    20 Jun 2004 15:15:07 -0000
183 @@ -43,7 +43,7 @@
184      double d;
185      double g = (double)min(guns, 7);
186  
187 -    d = ((double)(random() % 30) + 20.0) * ((double)g / 7.0);
188 +    d = ((double)(emp_random() % 30) + 20.0) * ((double)g / 7.0);
189      d *= ((double)effic);
190      d /= 100.0;
191      return d;
192 @@ -56,7 +56,7 @@
193  
194      d = 0.0;
195      while (guns--)
196 -       d += 10.0 + (double)(random() % 6);
197 +       d += 10.0 + (double)(emp_random() % 6);
198      d *= ((double)effic) * 0.01;
199      return d;
200  }
201 @@ -68,7 +68,7 @@
202  
203      shots = min(shots, guns);
204      while (shots-- > 0)
205 -       d += 5.0 + (double)(random() % 6);
206 +       d += 5.0 + (double)(emp_random() % 6);
207      d *= ((double)effic) * 0.01;
208      if (shells < ammo && ammo != 0)
209         d *= (double)((double)shells / (double)ammo);
210 Index: empserver/src/lib/subs/shpsub.c
211 --- empserver/src/lib/subs/shpsub.c     16 May 2004 14:19:36 -0000      1.13
212 +++ empserver/src/lib/subs/shpsub.c     20 Jun 2004 15:15:08 -0000
213 @@ -766,7 +766,7 @@
214  
215      nreport(sp->shp_own, N_HIT_MINE, 0, 1);
216  
217 -    m = 22.0 + (double)(random() % 21);
218 +    m = 22.0 + (double)(emp_random() % 21);
219      if (mcp->m_flags & M_SWEEP)
220         m /= 2.0;
221  
222 Index: empserver/src/lib/subs/takeover.c
223 --- empserver/src/lib/subs/takeover.c   4 Mar 2004 13:49:25 -0000       1.10
224 +++ empserver/src/lib/subs/takeover.c   20 Jun 2004 15:15:08 -0000
225 @@ -91,7 +91,7 @@
226             if (!(chance(LND_SPY_DETECT_CHANCE(lp->lnd_effic))))
227                 continue;
228         }
229 -       n = lp->lnd_effic - (30 + (random() % 100));
230 +       n = lp->lnd_effic - (30 + (emp_random() % 100));
231         if (n < 0)
232             n = 0;
233         lp->lnd_effic = n;
234 @@ -120,7 +120,7 @@
235       * how spunky are these guys?
236       * n: random number from -25:75 + (50 - loyalty)
237       */
238 -    n = (50 - sp->sct_loyal) + ((random() % 100) - 25);
239 +    n = (50 - sp->sct_loyal) + ((emp_random() % 100) - 25);
240      che_count = 0;
241      if (n > 0 && sp->sct_own == sp->sct_oldown) {
242         che_count = (civ * n / 3000) + 5;
243 @@ -178,7 +178,7 @@
244       * XXX If this was done right, planes could escape,
245       * flying to a nearby friendly airport.
246       */
247 -    n = pp->pln_effic - (30 + (random() % 100));
248 +    n = pp->pln_effic - (30 + (emp_random() % 100));
249      if (n < 0)
250         n = 0;
251      pp->pln_effic = n;
252 Index: empserver/src/lib/update/human.c
253 --- empserver/src/lib/update/human.c    14 May 2004 20:21:46 -0000      1.11
254 +++ empserver/src/lib/update/human.c    20 Jun 2004 15:15:09 -0000
255 @@ -123,7 +123,7 @@
256             sctwork = 0;
257         } else {
258             if (sp->sct_work < 100)
259 -               sctwork = sp->sct_work + 8 + (random() % 15);
260 +               sctwork = sp->sct_work + 8 + (emp_random() % 15);
261             if (sctwork > 100)
262                 sctwork = 100;
263             if (!player->simulation)
264 @@ -320,5 +320,5 @@
265  starvation(struct sctstr *sp)
266  {
267      sp->sct_work = 0;
268 -    sp->sct_loyal += (random() % 8) + 2;
269 +    sp->sct_loyal += (emp_random() % 8) + 2;
270  }
271 Index: empserver/src/lib/update/plague.c
272 --- empserver/src/lib/update/plague.c   11 Mar 2004 18:10:25 -0000      1.8
273 +++ empserver/src/lib/update/plague.c   20 Jun 2004 15:15:09 -0000
274 @@ -191,7 +191,7 @@
275      }
276      if (*ptime <= 0) {
277         *pstage -= 1;
278 -       *ptime = (etus / 2) + (random() % etus);
279 +       *ptime = (etus / 2) + (emp_random() % etus);
280      }
281      return stage;
282  }
283 Index: empserver/src/lib/update/populace.c
284 --- empserver/src/lib/update/populace.c 10 Mar 2004 17:59:37 -0000      1.3
285 +++ empserver/src/lib/update/populace.c 20 Jun 2004 15:15:09 -0000
286 @@ -87,7 +87,7 @@
287         n = roundavg(etu * 0.125);
288         if (n == 0)
289             n = 1;
290 -       n = sp->sct_loyal + (random() % n) + 1;
291 +       n = sp->sct_loyal + (emp_random() % n) + 1;
292         if (n > 127)
293             n = 127;
294         sp->sct_loyal = n;
295 @@ -95,7 +95,7 @@
296      if (sp->sct_loyal > 65 && mil < civ / 20) {
297         int work_red;
298  
299 -       work_red = sp->sct_loyal - (50 + (random() % 15));
300 +       work_red = sp->sct_loyal - (50 + (emp_random() % 15));
301         n = sp->sct_work - work_red;
302         if (n < 0)
303             n = 0;
304 Index: empserver/src/lib/update/revolt.c
305 --- empserver/src/lib/update/revolt.c   5 Mar 2004 10:38:57 -0000       1.10
306 +++ empserver/src/lib/update/revolt.c   20 Jun 2004 15:15:09 -0000
307 @@ -70,7 +70,7 @@
308      che_uw = 0;
309      che_civ = 0;
310      /* che due to civilian unrest */
311 -    n = 10 - (random() % 20);
312 +    n = 10 - (emp_random() % 20);
313      che_civ = 3 + (civ * n / 500);
314      if (che_civ < 0)
315         che_civ = 0;
316 @@ -81,7 +81,7 @@
317      che += che_civ;
318      if (che < CHE_MAX) {
319         /* che due to uw unrest */
320 -       n = 10 + (random() % 30);
321 +       n = 10 + (emp_random() % 30);
322         che_uw = 5 + (uw * n / 500);
323         if (che_uw > uw)
324             che_uw = uw;
325 @@ -252,7 +252,7 @@
326         }
327         if (mil > 0) {
328             /* military won.  */
329 -           n = sp->sct_loyal - (random() % 15);
330 +           n = sp->sct_loyal - (emp_random() % 15);
331             if (n < 0)
332                 n = 0;
333             sp->sct_loyal = n;
334 @@ -271,7 +271,7 @@
335          * Note this disrupts work in the sector.
336          */
337         n = 0;
338 -       n = (random() % 10) + (random() % che);
339 +       n = (emp_random() % 10) + (emp_random() % che);
340         if (n > 100)
341             n = 100;
342         tmp = sp->sct_work - n;
343 @@ -357,14 +357,14 @@
344         /* loyalty drops during recruitment efforts */
345         n = sp->sct_loyal;
346         if (n < 30)
347 -           n += (random() % 5) + 1;
348 +           n += (emp_random() % 5) + 1;
349         else if (n < 70)
350 -           n += (random() % 10) + 4;
351 +           n += (emp_random() % 10) + 4;
352         if (n > 127)
353             n = 127;
354         sp->sct_loyal = n;
355         if (sp->sct_oldown != sp->sct_own || n > 100) {
356 -           n = civ * (random() % 3) / 200;
357 +           n = civ * (emp_random() % 3) / 200;
358             n /= hap_fact(tnat, getnatp(sp->sct_oldown));
359             if (n + che > CHE_MAX)
360                 n = CHE_MAX - che;
361 @@ -372,7 +372,7 @@
362             civ -= n;
363             sp->sct_item[I_CIVIL] = civ;
364         }
365 -       n = uw * (random() % 3) / 200;
366 +       n = uw * (emp_random() % 3) / 200;
367         if (n + che > CHE_MAX)
368             n = CHE_MAX - che;
369         che += n;
370 @@ -405,7 +405,7 @@
371             val = roundintby(val, 10);
372             /* inject a modicum of indeterminism; also
373              * avoids che preferring certain directions */
374 -           val += random() % 10 - 5;
375 +           val += emp_random() % 10 - 5;
376             if (val >= min_mil)
377                 continue;
378             nicest_sp = nsp;
379 Index: empserver/src/util/fairland.c
380 --- empserver/src/util/fairland.c       23 Mar 2004 15:20:17 -0000      1.10
381 +++ empserver/src/util/fairland.c       20 Jun 2004 15:15:10 -0000
382 @@ -123,10 +123,10 @@
383  #define max(a,b) (a>b?a:b)
384  #endif
385  #ifndef SRANDOM
386 -#define SRANDOM srandom
387 +#define SRANDOM srand48
388  #endif
389  #ifndef RANDOM
390 -#define RANDOM random
391 +#define RANDOM lrand48
392  #endif
393  #define rnd(x) (RANDOM() % (x))
394  
395 Index: empserver/src/lib/gen/chance.c
396 --- empserver/src/lib/gen/chance.c      2 Sep 2003 20:48:48 -0000       1.2
397 +++ empserver/src/lib/gen/chance.c      20 Jun 2004 15:15:05 -0000
398 @@ -33,30 +33,34 @@
399  
400  #include "gen.h"
401  
402 -#ifdef hpux
403 +#ifndef        RANDOM
404 +#ifdef NOSVIDPRNG
405 +#define        RANDOM  random
406 +#define        SRANDOM srandom
407 +#else  /* ! NOSVIDPRNG */
408 +#define        RANDOM  lrand48
409 +#define        SRANDOM srand48
410 +#endif /* ! NOSVIDPRNG */
411 +#endif /* RANDOM */
412 +
413  void
414 -srandom(unsigned int n)
415 +emp_srandom(unsigned int n)
416  {
417 -    extern void srand48();
418 -
419 -    srand48(n);
420 +    SRANDOM(1);
421  }
422  
423  long
424 -random(void)
425 +emp_random(void)
426  {
427 -    extern long lrand48();
428 -
429 -    return (lrand48());                /* 5/28/91 by bailey@mcs.kent.edu */
430 +    return (RANDOM());         /* 5/28/91 by bailey@mcs.kent.edu */
431  }
432 -#endif
433  
434  int
435  chance(double d)
436  {
437      double roll;
438  
439 -    roll = (random() & 0x7fff);
440 +    roll = (emp_random() & 0x7fff);
441  
442      if (d > roll / 32768.0)
443         return 1;
444 @@ -66,7 +70,7 @@
445  int
446  roll(int n)
447  {
448 -    return (random() % n) + 1;
449 +    return (emp_random() % n) + 1;
450  }
451  
452  /*
453 Index: empserver/src/server/main.c
454 --- empserver/src/server/main.c 4 Apr 2004 14:20:30 -0000       1.12
455 +++ empserver/src/server/main.c 20 Jun 2004 17:38:12 -0000
456 @@ -195,7 +195,7 @@
457      empth_init((char **)&player, flags);
458      time(&now);
459  #if !defined(_WIN32)
460 -    srandom(now);
461 +    emp_srandom(now);
462  #else
463      srand(now);
464  #endif /* _WIN32 */
465 Index: empserver/src/server/update.c
466 --- empserver/src/server/update.c       4 Apr 2004 15:52:24 -0000       1.14
467 +++ empserver/src/server/update.c       20 Jun 2004 17:38:12 -0000
468 @@ -64,7 +64,7 @@
469         time(&now);
470         next_update_time(&now, &update_time, &delta);
471         if (update_window > 0) {
472 -           wind = (random() % update_window);
473 +           wind = (emp_random() % update_window);
474             update_time += wind;
475             delta += wind;
476         }