Encapsulate direct use of random(), srandom() in chance.c
Wrap roll0() around random(), and seed_prng() around srandom(). In preparation of replacing the PRNG.
This commit is contained in:
parent
8eb78a5a80
commit
866859e912
17 changed files with 87 additions and 49 deletions
|
@ -29,7 +29,7 @@
|
|||
* Known contributors to this file:
|
||||
* Dave Pare, 1986
|
||||
* Steve McClure, 1996
|
||||
* Markus Armbruster, 2004-2010
|
||||
* Markus Armbruster, 2004-2012
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -95,12 +95,12 @@ do_feed(struct sctstr *sp, struct natstr *np, short *vec,
|
|||
nreport(sp->sct_own, N_DIE_FAMINE, 0, 1);
|
||||
}
|
||||
sp->sct_work = 0;
|
||||
sp->sct_loyal += (random() % 8) + 2;
|
||||
sp->sct_loyal += roll0(8) + 2;
|
||||
}
|
||||
sctwork = 0;
|
||||
} else {
|
||||
if (sp->sct_work < 100)
|
||||
sctwork = sp->sct_work + 8 + (random() % 15);
|
||||
sctwork = sp->sct_work + 8 + roll0(15);
|
||||
if (sctwork > 100)
|
||||
sctwork = 100;
|
||||
if (!player->simulation)
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
*
|
||||
* Known contributors to this file:
|
||||
* Steve McClure, 1998-2000
|
||||
* Markus Armbruster, 2004-2012
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -182,7 +183,7 @@ plague_people(struct natstr *np, short *vec,
|
|||
}
|
||||
if (*ptime <= 0) {
|
||||
*pstage -= 1;
|
||||
*ptime = etus / 2 + random() % etus;
|
||||
*ptime = etus / 2 + roll0(etus);
|
||||
}
|
||||
return stage;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
*
|
||||
* Known contributors to this file:
|
||||
* Dave Pare, 1986
|
||||
* Markus Armbruster, 2004-2012
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -72,7 +73,7 @@ populace(struct natstr *np, struct sctstr *sp, int etu)
|
|||
n = roundavg(etu * 0.125);
|
||||
if (n == 0)
|
||||
n = 1;
|
||||
n = sp->sct_loyal + (random() % n) + 1;
|
||||
n = sp->sct_loyal + roll0(n) + 1;
|
||||
if (n > 127)
|
||||
n = 127;
|
||||
sp->sct_loyal = n;
|
||||
|
@ -80,7 +81,7 @@ populace(struct natstr *np, struct sctstr *sp, int etu)
|
|||
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 + roll0(15));
|
||||
n = sp->sct_work - work_red;
|
||||
if (n < 0)
|
||||
n = 0;
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
* Known contributors to this file:
|
||||
* Dave Pare, 1986
|
||||
* Steve McClure, 1997-2000
|
||||
* Markus Armbruster, 2004-2011
|
||||
* Markus Armbruster, 2004-2012
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -66,7 +66,7 @@ revolt(struct sctstr *sp)
|
|||
return;
|
||||
che_uw = 0;
|
||||
/* che due to civilian unrest */
|
||||
n = 10 - (random() % 20);
|
||||
n = 10 - roll0(20);
|
||||
che_civ = 3 + (civ * n / 500);
|
||||
if (che_civ < 0)
|
||||
che_civ = 0;
|
||||
|
@ -77,7 +77,7 @@ revolt(struct sctstr *sp)
|
|||
che += che_civ;
|
||||
if (che < CHE_MAX) {
|
||||
/* che due to uw unrest */
|
||||
n = 10 + (random() % 30);
|
||||
n = 10 + roll0(30);
|
||||
che_uw = 5 + (uw * n / 500);
|
||||
if (che_uw > uw)
|
||||
che_uw = uw;
|
||||
|
@ -240,7 +240,7 @@ guerrilla(struct sctstr *sp)
|
|||
}
|
||||
if (mil > 0) {
|
||||
/* military won. */
|
||||
n = sp->sct_loyal - (random() % 15);
|
||||
n = sp->sct_loyal - roll0(15);
|
||||
if (n < 0)
|
||||
n = 0;
|
||||
sp->sct_loyal = n;
|
||||
|
@ -254,7 +254,7 @@ guerrilla(struct sctstr *sp)
|
|||
* guerrillas have to resort to blowing things up.
|
||||
* Note this disrupts work in the sector.
|
||||
*/
|
||||
n = (random() % 10) + (random() % che);
|
||||
n = roll0(10) + roll0(che);
|
||||
if (n > 100)
|
||||
n = 100;
|
||||
tmp = sp->sct_work - n;
|
||||
|
@ -327,14 +327,14 @@ guerrilla(struct sctstr *sp)
|
|||
/* loyalty drops during recruitment efforts */
|
||||
n = sp->sct_loyal;
|
||||
if (n < 30)
|
||||
n += (random() % 5) + 1;
|
||||
n += roll0(5) + 1;
|
||||
else if (n < 70)
|
||||
n += (random() % 10) + 4;
|
||||
n += roll0(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 * roll0(3) / 200;
|
||||
n /= hap_fact(tnat, getnatp(sp->sct_oldown));
|
||||
if (n + che > CHE_MAX)
|
||||
n = CHE_MAX - che;
|
||||
|
@ -342,7 +342,7 @@ guerrilla(struct sctstr *sp)
|
|||
civ -= n;
|
||||
sp->sct_item[I_CIVIL] = civ;
|
||||
}
|
||||
n = uw * (random() % 3) / 200;
|
||||
n = uw * roll0(3) / 200;
|
||||
if (n + che > CHE_MAX)
|
||||
n = CHE_MAX - che;
|
||||
che += n;
|
||||
|
@ -375,7 +375,7 @@ domove:
|
|||
val = roundintby(val, 10);
|
||||
/* inject a modicum of indeterminism; also
|
||||
* avoids che preferring certain directions */
|
||||
val += random() % 10 - 5;
|
||||
val += roll0(10) - 5;
|
||||
if (val >= min_mil)
|
||||
continue;
|
||||
nicest_sp = nsp;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue