455 lines
14 KiB
Diff
455 lines
14 KiB
Diff
Index: empserver/include/damage.h
|
|
--- empserver/include/damage.h 16 Mar 2005 21:51:57 -0000 1.3
|
|
+++ empserver/include/damage.h 17 Mar 2005 10:01:13 -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 23 Oct 2005 08:32:49 -0000 1.92
|
|
+++ empserver/include/prototypes.h 24 Oct 2005 15:27:54 -0000
|
|
@@ -387,6 +387,9 @@
|
|
extern int ldround(double, int);
|
|
extern int roundintby(int, int);
|
|
extern int scthash(register int, register int, int);
|
|
+/* 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 16 Mar 2005 21:56:00 -0000 1.10
|
|
+++ empserver/src/lib/commands/anti.c 17 Mar 2005 10:01:14 -0000
|
|
@@ -130,7 +130,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 16 Mar 2005 21:56:01 -0000 1.10
|
|
+++ empserver/src/lib/commands/laun.c 17 Mar 2005 10:01:14 -0000
|
|
@@ -420,7 +420,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 16 Mar 2005 21:56:02 -0000 1.23
|
|
+++ empserver/src/lib/commands/mfir.c 17 Mar 2005 10:01:14 -0000
|
|
@@ -558,7 +558,7 @@
|
|
/* 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 23 Oct 2005 20:52:46 -0000 1.24
|
|
+++ empserver/src/lib/commands/new.c 24 Oct 2005 15:30:24 -0000
|
|
@@ -102,8 +102,8 @@
|
|
} else {
|
|
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 16 Mar 2005 21:56:02 -0000 1.9
|
|
+++ empserver/src/lib/commands/news.c 17 Mar 2005 10:01:14 -0000
|
|
@@ -188,7 +188,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;
|
|
@@ -198,7 +198,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 16 Mar 2005 21:56:03 -0000 1.11
|
|
+++ empserver/src/lib/commands/sabo.c 17 Mar 2005 10:01:14 -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 16 Mar 2005 21:56:04 -0000 1.11
|
|
+++ empserver/src/lib/common/damage.c 17 Mar 2005 10:01:14 -0000
|
|
@@ -177,7 +177,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 16 Mar 2005 21:56:05 -0000 1.5
|
|
+++ empserver/src/lib/gen/chance.c 17 Mar 2005 10:01:14 -0000
|
|
@@ -31,14 +31,37 @@
|
|
*
|
|
*/
|
|
|
|
+#include <stdlib.h>
|
|
#include "gen.h"
|
|
|
|
+#ifndef RANDOM
|
|
+#ifdef NOSVIDPRNG
|
|
+#define RANDOM random
|
|
+#define SRANDOM srandom
|
|
+#else /* ! NOSVIDPRNG */
|
|
+#define RANDOM lrand48
|
|
+#define SRANDOM srand48
|
|
+#endif /* ! NOSVIDPRNG */
|
|
+#endif /* ! RANDOM */
|
|
+
|
|
+void
|
|
+emp_srandom(unsigned int n)
|
|
+{
|
|
+ SRANDOM(1);
|
|
+}
|
|
+
|
|
+long
|
|
+emp_random(void)
|
|
+{
|
|
+ return (RANDOM()); /* 5/28/91 by bailey@mcs.kent.edu */
|
|
+}
|
|
+
|
|
int
|
|
chance(double d)
|
|
{
|
|
double roll;
|
|
|
|
- roll = (random() & 0x7fff);
|
|
+ roll = (emp_random() & 0x7fff);
|
|
|
|
if (d > roll / 32768.0)
|
|
return 1;
|
|
@@ -48,7 +71,7 @@
|
|
int
|
|
roll(int n)
|
|
{
|
|
- return (random() % n) + 1;
|
|
+ return (emp_random() % n) + 1;
|
|
}
|
|
|
|
/*
|
|
Index: empserver/src/lib/subs/attsub.c
|
|
--- empserver/src/lib/subs/attsub.c 2 Oct 2005 14:35:18 -0000 1.30
|
|
+++ empserver/src/lib/subs/attsub.c 4 Oct 2005 14:57:37 -0000
|
|
@@ -1863,12 +1863,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("!");
|
|
@@ -1884,9 +1884,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 16 Mar 2005 21:57:53 -0000 1.5
|
|
+++ empserver/src/lib/subs/landgun.c 17 Mar 2005 10:01:14 -0000
|
|
@@ -40,7 +40,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;
|
|
@@ -53,7 +53,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;
|
|
}
|
|
@@ -65,7 +65,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 3 Oct 2005 14:47:59 -0000 1.22
|
|
+++ empserver/src/lib/subs/shpsub.c 4 Oct 2005 14:57:37 -0000
|
|
@@ -759,7 +759,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 16 Mar 2005 21:57:55 -0000 1.14
|
|
+++ empserver/src/lib/subs/takeover.c 17 Mar 2005 10:01:14 -0000
|
|
@@ -91,7 +91,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;
|
|
@@ -120,7 +120,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;
|
|
@@ -178,7 +178,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
|
|
diff -u -r1.18 human.c
|
|
--- empserver/src/lib/update/human.c 2 Oct 2005 19:10:16 -0000 1.18
|
|
+++ empserver/src/lib/update/human.c 4 Oct 2005 14:57:37 -0000
|
|
@@ -116,12 +116,12 @@
|
|
nreport(sp->sct_own, N_DIE_FAMINE, 0, 1);
|
|
}
|
|
sp->sct_work = 0;
|
|
- sp->sct_loyal += (random() % 8) + 2;
|
|
+ sp->sct_loyal += (emp_random() % 8) + 2;
|
|
}
|
|
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)
|
|
Index: empserver/src/lib/update/plague.c
|
|
--- empserver/src/lib/update/plague.c 16 Mar 2005 21:57:57 -0000 1.15
|
|
+++ empserver/src/lib/update/plague.c 17 Mar 2005 10:01:15 -0000
|
|
@@ -190,7 +190,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 16 Mar 2005 21:57:57 -0000 1.9
|
|
+++ empserver/src/lib/update/populace.c 17 Mar 2005 10:01:15 -0000
|
|
@@ -85,7 +85,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;
|
|
@@ -93,7 +93,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 31 Jul 2005 13:55:49 -0000 1.16
|
|
+++ empserver/src/lib/update/revolt.c 11 Aug 2005 09:14:25 -0000
|
|
@@ -70,7 +70,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;
|
|
@@ -81,7 +81,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;
|
|
@@ -252,7 +252,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;
|
|
@@ -271,7 +271,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;
|
|
@@ -351,14 +351,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;
|
|
@@ -366,7 +366,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;
|
|
@@ -399,7 +399,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/server/main.c
|
|
--- empserver/src/server/main.c 3 May 2005 00:06:10 -0000 1.62
|
|
+++ empserver/src/server/main.c 28 May 2005 08:32:40 -0000
|
|
@@ -255,7 +255,7 @@
|
|
void
|
|
init_server(void)
|
|
{
|
|
- srandom(time(NULL));
|
|
+ emp_srandom(time(NULL));
|
|
#if defined(_WIN32)
|
|
loc_NTInit();
|
|
#endif
|
|
Index: empserver/src/server/update.c
|
|
--- empserver/src/server/update.c 16 Mar 2005 21:57:58 -0000 1.18
|
|
+++ empserver/src/server/update.c 17 Mar 2005 10:01:15 -0000
|
|
@@ -70,7 +70,7 @@
|
|
time(&now);
|
|
next_update_time(&now, &update_time, &delta);
|
|
if (update_window > 0) {
|
|
- wind = (random() % update_window);
|
|
+ wind = (emp_random() % update_window);
|
|
update_time += wind;
|
|
delta += wind;
|
|
}
|
|
Index: empserver/src/util/fairland.c
|
|
--- empserver/src/util/fairland.c 16 Mar 2005 22:03:16 -0000 1.25
|
|
+++ empserver/src/util/fairland.c 17 Mar 2005 10:01:15 -0000
|
|
@@ -126,7 +126,7 @@
|
|
#if !defined(_WIN32)
|
|
#define max(a,b) (a>b?a:b)
|
|
#endif
|
|
-#define rnd(x) (random() % (x))
|
|
+#define rnd(x) (lrand48() % (x))
|
|
|
|
int secs; /* number of sectors grown */
|
|
int ctot; /* total number of continents and islands grown */
|
|
@@ -229,7 +229,7 @@
|
|
exit(1);
|
|
}
|
|
}
|
|
- srandom(rnd_seed);
|
|
+ srand48(rnd_seed);
|
|
if (emp_config(config_file))
|
|
exit(1);
|
|
|