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