Merge branch 'NetHack-3.6.2'

This commit is contained in:
nhmall
2019-01-29 07:27:56 -05:00
50 changed files with 778 additions and 205 deletions

View File

@@ -239,7 +239,7 @@ int rx, ry, *resp;
int visglyph, corpseglyph;
visglyph = glyph_at(rx, ry);
corpseglyph = obj_to_glyph(corpse);
corpseglyph = obj_to_glyph(corpse, rn2);
if (Blind && (visglyph != corpseglyph))
map_object(corpse, TRUE);
@@ -2491,7 +2491,7 @@ struct obj *otmp;
if (otmp == g.trapinfo.tobj && u.ux == g.trapinfo.tx
&& u.uy == g.trapinfo.ty) {
You("resume setting %s%s.", shk_your(buf, otmp),
defsyms[trap_to_defsym(what_trap(ttyp))].explanation);
defsyms[trap_to_defsym(what_trap(ttyp, rn2))].explanation);
set_occupation(set_trap, occutext, 0);
return;
}
@@ -2516,7 +2516,8 @@ struct obj *otmp;
chance = (rnl(10) > 5);
You("aren't very skilled at reaching from %s.", mon_nam(u.usteed));
Sprintf(buf, "Continue your attempt to set %s?",
the(defsyms[trap_to_defsym(what_trap(ttyp))].explanation));
the(defsyms[trap_to_defsym(what_trap(ttyp, rn2))]
.explanation));
if (yn(buf) == 'y') {
if (chance) {
switch (ttyp) {
@@ -2527,7 +2528,7 @@ struct obj *otmp;
case BEAR_TRAP: /* drop it without arming it */
reset_trapset();
You("drop %s!",
the(defsyms[trap_to_defsym(what_trap(ttyp))]
the(defsyms[trap_to_defsym(what_trap(ttyp, rn2))]
.explanation));
dropx(otmp);
return;
@@ -2539,7 +2540,7 @@ struct obj *otmp;
}
}
You("begin setting %s%s.", shk_your(buf, otmp),
defsyms[trap_to_defsym(what_trap(ttyp))].explanation);
defsyms[trap_to_defsym(what_trap(ttyp, rn2))].explanation);
set_occupation(set_trap, occutext, 0);
return;
}
@@ -2572,7 +2573,7 @@ set_trap()
}
if (!g.trapinfo.force_bungle)
You("finish arming %s.",
the(defsyms[trap_to_defsym(what_trap(ttyp))].explanation));
the(defsyms[trap_to_defsym(what_trap(ttyp, rn2))].explanation));
if (((otmp->cursed || Fumbling) && (rnl(10) > 5))
|| g.trapinfo.force_bungle)
dotrap(ttmp,

View File

@@ -21,6 +21,7 @@ const schar ydir[10] = { 0, -1, -1, -1, 0, 1, 1, 1, 0, 0 };
const schar zdir[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, -1 };
NEARDATA struct flag flags;
NEARDATA boolean has_strong_rngseed = FALSE;
#ifdef SYSFLAGS
NEARDATA struct sysflag sysflags;
#endif

View File

@@ -76,10 +76,12 @@ struct monst *mtmp;
boolean showtail;
{
if (def_monsyms[(int) mtmp->data->mlet].sym == ' ')
show_glyph(mtmp->mx, mtmp->my, detected_mon_to_glyph(mtmp));
else
show_glyph(mtmp->mx, mtmp->my,
mtmp->mtame ? pet_to_glyph(mtmp) : mon_to_glyph(mtmp));
detected_mon_to_glyph(mtmp, newsym_rn2));
else
show_glyph(mtmp->mx, mtmp->my, mtmp->mtame
? pet_to_glyph(mtmp, newsym_rn2)
: mon_to_glyph(mtmp, newsym_rn2));
if (showtail && mtmp->data == &mons[PM_LONG_WORM])
detect_wsegs(mtmp, 0);
@@ -865,10 +867,10 @@ int src_cursed;
obj.ox = x;
obj.oy = y;
}
obj.otyp = !Hallucination ? GOLD_PIECE : random_object();
obj.otyp = !Hallucination ? GOLD_PIECE : random_object(rn2);
obj.quan = (long) ((obj.otyp == GOLD_PIECE) ? rnd(10)
: objects[obj.otyp].oc_merge ? rnd(2) : 1);
obj.corpsenm = random_monster(); /* if otyp == CORPSE */
obj.corpsenm = random_monster(rn2); /* if otyp == CORPSE */
map_object(&obj, 1);
} else if (trap) {
map_trap(trap, 1);
@@ -1589,14 +1591,20 @@ void
find_trap(trap)
struct trap *trap;
{
int tt = what_trap(trap->ttyp);
int tt = what_trap(trap->ttyp, rn2);
boolean cleared = FALSE;
trap->tseen = 1;
exercise(A_WIS, TRUE);
feel_newsym(trap->tx, trap->ty);
if (levl[trap->tx][trap->ty].glyph != trap_to_glyph(trap)) {
/* The "Hallucination ||" is to preserve 3.6.1 behaviour, but this
behaviour might need a rework in the hallucination case
(e.g. to not prompt if any trap glyph appears on the
square). */
if (Hallucination ||
levl[trap->tx][trap->ty].glyph !=
trap_to_glyph(trap, rn2_on_display_rng)) {
/* There's too much clutter to see your find otherwise */
cls();
map_trap(trap, 1);
@@ -1830,7 +1838,7 @@ int default_glyph, which_subset;
an object, replacing any object or trap at its spot) */
glyph = !swallowed ? glyph_at(x, y) : levl_glyph;
if (keep_mons && x == u.ux && y == u.uy && swallowed)
glyph = mon_to_glyph(u.ustuck);
glyph = mon_to_glyph(u.ustuck, rn2_on_display_rng);
else if (((glyph_is_monster(glyph)
|| glyph_is_warning(glyph)) && !keep_mons)
|| glyph_is_swallow(glyph))
@@ -1839,7 +1847,7 @@ int default_glyph, which_subset;
|| glyph_is_invisible(glyph))
&& keep_traps && !covers_traps(x, y)) {
if ((t = t_at(x, y)) != 0 && t->tseen)
glyph = trap_to_glyph(t);
glyph = trap_to_glyph(t, rn2_on_display_rng);
}
if ((glyph_is_object(glyph) && !keep_objs)
|| (glyph_is_trap(glyph) && !keep_traps)

View File

@@ -222,7 +222,7 @@ register struct trap *trap;
register int show;
{
register int x = trap->tx, y = trap->ty;
register int glyph = trap_to_glyph(trap);
register int glyph = trap_to_glyph(trap, newsym_rn2);
if (g.level.flags.hero_memory)
levl[x][y].glyph = glyph;
@@ -242,14 +242,14 @@ register struct obj *obj;
register int show;
{
register int x = obj->ox, y = obj->oy;
register int glyph = obj_to_glyph(obj);
register int glyph = obj_to_glyph(obj, newsym_rn2);
if (g.level.flags.hero_memory) {
/* MRKR: While hallucinating, statues are seen as random monsters */
/* but remembered as random objects. */
if (Hallucination && obj->otyp == STATUE) {
levl[x][y].glyph = random_obj_to_glyph();
levl[x][y].glyph = random_obj_to_glyph(newsym_rn2);
} else {
levl[x][y].glyph = glyph;
}
@@ -394,7 +394,7 @@ xchar worm_tail; /* mon is actually a worm tail */
(int) mon->m_ap_type);
/*FALLTHRU*/
case M_AP_NOTHING:
show_glyph(x, y, mon_to_glyph(mon));
show_glyph(x, y, mon_to_glyph(mon, newsym_rn2));
break;
case M_AP_FURNITURE: {
@@ -434,7 +434,8 @@ xchar worm_tail; /* mon is actually a worm tail */
case M_AP_MONSTER:
show_glyph(x, y,
monnum_to_glyph(what_mon((int) mon->mappearance)));
monnum_to_glyph(what_mon((int) mon->mappearance,
rn2_on_display_rng)));
break;
}
}
@@ -456,17 +457,19 @@ xchar worm_tail; /* mon is actually a worm tail */
if (worm_tail)
num = petnum_to_glyph(PM_LONG_WORM_TAIL);
else
num = pet_to_glyph(mon);
num = pet_to_glyph(mon, rn2_on_display_rng);
} else if (sightflags == DETECTED) {
if (worm_tail)
num = detected_monnum_to_glyph(what_mon(PM_LONG_WORM_TAIL));
num = detected_monnum_to_glyph(
what_mon(PM_LONG_WORM_TAIL, rn2_on_display_rng));
else
num = detected_mon_to_glyph(mon);
num = detected_mon_to_glyph(mon, rn2_on_display_rng);
} else {
if (worm_tail)
num = monnum_to_glyph(what_mon(PM_LONG_WORM_TAIL));
num = monnum_to_glyph(
what_mon(PM_LONG_WORM_TAIL, rn2_on_display_rng));
else
num = mon_to_glyph(mon);
num = mon_to_glyph(mon, rn2_on_display_rng);
}
show_glyph(x, y, num);
}
@@ -489,10 +492,11 @@ register struct monst *mon;
int glyph;
if (mon_warning(mon)) {
int wl = Hallucination ? rn1(WARNCOUNT - 1, 1) : warning_of(mon);
int wl = Hallucination ?
rn2_on_display_rng(WARNCOUNT - 1) + 1 : warning_of(mon);
glyph = warning_to_glyph(wl);
} else if (MATCH_WARN_OF_MON(mon)) {
glyph = mon_to_glyph(mon);
glyph = mon_to_glyph(mon, rn2_on_display_rng);
} else {
impossible("display_warning did not match warning type?");
return;
@@ -1742,7 +1746,8 @@ int loc;
impossible("swallow_to_glyph: bad swallow location");
loc = S_sw_br;
}
return ((int) (what_mon(mnum) << 3) | (loc - S_sw_tl)) + GLYPH_SWALLOW_OFF;
return ((int) (what_mon(mnum, rn2_on_display_rng) << 3) |
(loc - S_sw_tl)) + GLYPH_SWALLOW_OFF;
}
/*

View File

@@ -1413,6 +1413,8 @@ boolean at_stairs, falling, portal;
/* we'll reach here if running in wizard mode */
error("Cannot continue this game.");
}
reseed_random(rn2);
reseed_random(rn2_on_display_rng);
minit(); /* ZEROCOMP */
getlev(fd, g.hackpid, new_ledger, FALSE);
(void) nhclose(fd);

View File

@@ -1533,8 +1533,12 @@ namefloorobj()
unames[0] = ((Upolyd ? u.mfemale : flags.female) && g.urole.name.f)
? g.urole.name.f
: g.urole.name.m;
/* random rank title for hero's role */
unames[1] = rank_of(rnd(30), Role_switch, flags.female);
/* random rank title for hero's role
note: the 30 is hardcoded in xlev_to_rank, so should be
hardcoded here too */
unames[1] = rank_of(rn2_on_display_rng(30) + 1,
Role_switch, flags.female);
/* random fake monster */
unames[2] = bogusmon(tmpbuf, (char *) 0);
/* increased chance for fake monster */
@@ -1545,7 +1549,7 @@ namefloorobj()
unames[5] = "Wibbly Wobbly";
pline("%s %s to call you \"%s.\"",
The(buf), use_plural ? "decide" : "decides",
unames[rn2(SIZE(unames))]);
unames[rn2_on_display_rng(SIZE(unames))]);
} else if (!objtyp_is_callable(obj->otyp)) {
pline("%s %s can't be assigned a type name.",
use_plural ? "Those" : "That", buf);
@@ -1925,7 +1929,7 @@ char *buf, *code;
{
char *mname = buf;
get_rnd_text(BOGUSMONFILE, buf);
get_rnd_text(BOGUSMONFILE, buf, rn2_on_display_rng);
/* strip prefix if present */
if (!letter(*mname)) {
if (code)
@@ -1952,7 +1956,7 @@ char *code;
*code = '\0';
do {
name = rn1(SPECIAL_PM + BOGUSMONSIZE - LOW_PM, LOW_PM);
name = rn2_on_display_rng(SPECIAL_PM + BOGUSMONSIZE - LOW_PM) + LOW_PM;
} while (name < SPECIAL_PM
&& (type_is_pname(&mons[name]) || (mons[name].geno & G_NOGEN)));
@@ -2008,8 +2012,9 @@ const char *
hcolor(colorpref)
const char *colorpref;
{
return (Hallucination || !colorpref) ? hcolors[rn2(SIZE(hcolors))]
: colorpref;
return (Hallucination || !colorpref)
? hcolors[rn2_on_display_rng(SIZE(hcolors))]
: colorpref;
}
/* return a random real color unless hallucinating */

View File

@@ -1074,7 +1074,7 @@ struct obj *obj;
if ((u.dx || u.dy) && (g.bhitpos.x != u.ux || g.bhitpos.y != u.uy)) {
int x = g.bhitpos.x - u.dx, y = g.bhitpos.y - u.dy;
tmp_at(DISP_FLASH, obj_to_glyph(obj));
tmp_at(DISP_FLASH, obj_to_glyph(obj, rn2_on_display_rng));
while (isok(x,y) && (x != u.ux || y != u.uy)) {
tmp_at(x, y);
delay_output();
@@ -1143,7 +1143,7 @@ boolean twoweap; /* used to restore twoweapon mode if wielded weapon returns */
g.bhitpos.x = mon->mx;
g.bhitpos.y = mon->my;
if (tethered_weapon)
tmp_at(DISP_TETHER, obj_to_glyph(obj));
tmp_at(DISP_TETHER, obj_to_glyph(obj, rn2_on_display_rng));
} else if (u.dz) {
if (u.dz < 0
/* Mjollnir must we wielded to be thrown--caller verifies this;
@@ -1372,7 +1372,7 @@ boolean twoweap; /* used to restore twoweapon mode if wielded weapon returns */
}
if (!IS_SOFT(levl[g.bhitpos.x][g.bhitpos.y].typ) && breaktest(obj)) {
tmp_at(DISP_FLASH, obj_to_glyph(obj));
tmp_at(DISP_FLASH, obj_to_glyph(obj, rn2_on_display_rng));
tmp_at(g.bhitpos.x, g.bhitpos.y);
delay_output();
tmp_at(DISP_END, 0);

View File

@@ -18,7 +18,7 @@ char *outbuf;
/* a random engraving may come from the "rumors" file,
or from the "engrave" file (formerly in an array here) */
if (!rn2(4) || !(rumor = getrumor(0, outbuf, TRUE)) || !*rumor)
(void) get_rnd_text(ENGRAVEFILE, outbuf);
(void) get_rnd_text(ENGRAVEFILE, outbuf, rn2);
wipeout_text(outbuf, (int) (strlen(outbuf) / 4), 0);
return outbuf;
@@ -1294,7 +1294,7 @@ const char *str;
/* Engrave the headstone */
del_engr_at(x, y);
if (!str)
str = get_rnd_text(EPITAPHFILE, buf);
str = get_rnd_text(EPITAPHFILE, buf, rn2);
make_engr_at(x, y, str, 0L, HEADSTONE);
return;
}

View File

@@ -1464,7 +1464,7 @@ domove_core()
if (g.context.run >= 2) {
if (iflags.mention_walls) {
if (trap && trap->tseen) {
int tt = what_trap(trap->ttyp);
int tt = what_trap(trap->ttyp, rn2_on_display_rng);
You("stop in front of %s.",
an(defsyms[trap_to_defsym(tt)].explanation));
@@ -2708,7 +2708,7 @@ lookaround()
goto bcorr; /* if you must */
if (x == u.ux + u.dx && y == u.uy + u.dy) {
if (iflags.mention_walls) {
int tt = what_trap(trap->ttyp);
int tt = what_trap(trap->ttyp, rn2_on_display_rng);
You("stop in front of %s.",
an(defsyms[trap_to_defsym(tt)].explanation));
}

View File

@@ -51,6 +51,8 @@
boolean fuzzymatch (const char *, const char *,
const char *, boolean)
void setrandom (void)
void init_random (fn)
void reseed_random (fn)
time_t getnow (void)
int getyear (void)
char * yymmdd (time_t)
@@ -848,44 +850,69 @@ extern struct tm *FDECL(localtime, (time_t *));
#endif
STATIC_DCL struct tm *NDECL(getlt);
void
setrandom()
/* Sets the seed for the random number generator */
#ifdef USE_ISAAC64
static void
set_random(seed, fn)
unsigned long seed;
int FDECL((*fn), (int));
{
init_isaac64(seed, fn);
}
#else /* USE_ISAAC64 */
static void
set_random(seed, fn)
unsigned long seed;
int FDECL((*fn),(int));
{
unsigned long seed = (unsigned long) getnow(); /* time((TIME_type) 0) */
#if defined(UNIX) || defined(VMS)
{
unsigned long pid = (unsigned long) getpid();
/* Quick dirty band-aid to prevent PRNG prediction */
if (pid) {
if (!(pid & 3L))
pid -= 1L;
seed *= pid;
}
}
#endif
/* the types are different enough here that sweeping the different
* routine names into one via #defines is even more confusing
*/
#ifdef RANDOM /* srandom() from sys/share/random.c */
# ifdef RANDOM /* srandom() from sys/share/random.c */
srandom((unsigned int) seed);
#else
#if defined(__APPLE__) || defined(BSD) || defined(LINUX) || defined(ULTRIX) \
# else
# if defined(__APPLE__) || defined(BSD) || defined(LINUX) || defined(ULTRIX) \
|| defined(CYGWIN32) /* system srandom() */
#if defined(BSD) && !defined(POSIX_TYPES) && defined(SUNOS4)
# if defined(BSD) && !defined(POSIX_TYPES) && defined(SUNOS4)
(void)
#endif
# endif
srandom((int) seed);
#else
#ifdef UNIX /* system srand48() */
# else
# ifdef UNIX /* system srand48() */
srand48((long) seed);
#else /* poor quality system routine */
# else /* poor quality system routine */
srand((int) seed);
#endif
#endif
#endif
# endif
# endif
# endif
}
#endif /* USE_ISAAC64 */
/* An appropriate version of this must always be provided in
port-specific code somewhere. It returns a number suitable
as seed for the random number generator */
extern unsigned long NDECL(sys_random_seed);
/*
* Initializes the random number generator.
* Only call once.
*/
void
init_random(fn)
int FDECL((*fn),(int));
{
set_random(sys_random_seed(), fn);
}
/* Reshuffles the random number generator. */
void
reseed_random(fn)
int FDECL((*fn),(int));
{
/* only reseed if we are certain that the seed generation is unguessable
* by the players. */
if (has_strong_rngseed)
init_random(fn);
}
time_t

View File

@@ -2681,8 +2681,8 @@ long *out_cnt;
any.a_obj = otmp;
else
any.a_char = ilet;
add_menu(win, obj_to_glyph(otmp), &any, ilet, 0, ATR_NONE,
doname(otmp), MENU_UNSELECTED);
add_menu(win, obj_to_glyph(otmp, rn2_on_display_rng), &any, ilet,
0, ATR_NONE, doname(otmp), MENU_UNSELECTED);
}
}
if (flags.sortpack) {
@@ -2795,7 +2795,8 @@ char avoidlet;
classcount++;
}
any.a_char = ilet;
add_menu(win, obj_to_glyph(otmp), &any, ilet, 0, ATR_NONE,
add_menu(win, obj_to_glyph(otmp, rn2_on_display_rng),
&any, ilet, 0, ATR_NONE,
doname(otmp), MENU_UNSELECTED);
}
}

161
src/isaac64.c Normal file
View File

@@ -0,0 +1,161 @@
/*Written by Timothy B. Terriberry (tterribe@xiph.org) 1999-2009
CC0 (Public domain) - see http://creativecommons.org/publicdomain/zero/1.0/ for details
Based on the public domain ISAAC implementation by Robert J. Jenkins Jr.*/
#include <math.h>
#include <string.h>
#include "isaac64.h"
#define ISAAC64_MASK ((uint64_t)0xFFFFFFFFFFFFFFFFULL)
#if (defined(__STDC__) && __STDC_VERSION__ >= 199901L)
#define HAS_INLINE
#endif
/* Extract ISAAC64_SZ_LOG bits (starting at bit 3). */
#ifdef HAS_INLINE
static inline uint32_t lower_bits(uint64_t x)
#else
static uint32_t lower_bits(uint64_t x)
#endif
{
return (x & ((ISAAC64_SZ-1) << 3)) >>3;
}
/* Extract next ISAAC64_SZ_LOG bits (starting at bit ISAAC64_SZ_LOG+2). */
#ifdef HAS_INLINE
static inline uint32_t upper_bits(uint64_t y)
#else
static uint32_t upper_bits(uint64_t y)
#endif
{
return (y >> (ISAAC64_SZ_LOG+3)) & (ISAAC64_SZ-1);
}
static void isaac64_update(isaac64_ctx *_ctx){
uint64_t *m;
uint64_t *r;
uint64_t a;
uint64_t b;
uint64_t x;
uint64_t y;
int i;
m=_ctx->m;
r=_ctx->r;
a=_ctx->a;
b=_ctx->b+(++_ctx->c);
for(i=0;i<ISAAC64_SZ/2;i++){
x=m[i];
a=~(a^a<<21)+m[i+ISAAC64_SZ/2];
m[i]=y=m[lower_bits(x)]+a+b;
r[i]=b=m[upper_bits(y)]+x;
x=m[++i];
a=(a^a>>5)+m[i+ISAAC64_SZ/2];
m[i]=y=m[lower_bits(x)]+a+b;
r[i]=b=m[upper_bits(y)]+x;
x=m[++i];
a=(a^a<<12)+m[i+ISAAC64_SZ/2];
m[i]=y=m[lower_bits(x)]+a+b;
r[i]=b=m[upper_bits(y)]+x;
x=m[++i];
a=(a^a>>33)+m[i+ISAAC64_SZ/2];
m[i]=y=m[lower_bits(x)]+a+b;
r[i]=b=m[upper_bits(y)]+x;
}
for(i=ISAAC64_SZ/2;i<ISAAC64_SZ;i++){
x=m[i];
a=~(a^a<<21)+m[i-ISAAC64_SZ/2];
m[i]=y=m[lower_bits(x)]+a+b;
r[i]=b=m[upper_bits(y)]+x;
x=m[++i];
a=(a^a>>5)+m[i-ISAAC64_SZ/2];
m[i]=y=m[lower_bits(x)]+a+b;
r[i]=b=m[upper_bits(y)]+x;
x=m[++i];
a=(a^a<<12)+m[i-ISAAC64_SZ/2];
m[i]=y=m[lower_bits(x)]+a+b;
r[i]=b=m[upper_bits(y)]+x;
x=m[++i];
a=(a^a>>33)+m[i-ISAAC64_SZ/2];
m[i]=y=m[lower_bits(x)]+a+b;
r[i]=b=m[upper_bits(y)]+x;
}
_ctx->b=b;
_ctx->a=a;
_ctx->n=ISAAC64_SZ;
}
static void isaac64_mix(uint64_t _x[8]){
static const unsigned char SHIFT[8]={9,9,23,15,14,20,17,14};
int i;
for(i=0;i<8;i++){
_x[i]-=_x[(i+4)&7];
_x[(i+5)&7]^=_x[(i+7)&7]>>SHIFT[i];
_x[(i+7)&7]+=_x[i];
i++;
_x[i]-=_x[(i+4)&7];
_x[(i+5)&7]^=_x[(i+7)&7]<<SHIFT[i];
_x[(i+7)&7]+=_x[i];
}
}
void isaac64_init(isaac64_ctx *_ctx,const unsigned char *_seed,int _nseed){
_ctx->a=_ctx->b=_ctx->c=0;
memset(_ctx->r,0,sizeof(_ctx->r));
isaac64_reseed(_ctx,_seed,_nseed);
}
void isaac64_reseed(isaac64_ctx *_ctx,const unsigned char *_seed,int _nseed){
uint64_t *m;
uint64_t *r;
uint64_t x[8];
int i;
int j;
m=_ctx->m;
r=_ctx->r;
if(_nseed>ISAAC64_SEED_SZ_MAX)_nseed=ISAAC64_SEED_SZ_MAX;
for(i=0;i<_nseed>>3;i++){
r[i]^=(uint64_t)_seed[i<<3|7]<<56|(uint64_t)_seed[i<<3|6]<<48|
(uint64_t)_seed[i<<3|5]<<40|(uint64_t)_seed[i<<3|4]<<32|
(uint64_t)_seed[i<<3|3]<<24|(uint64_t)_seed[i<<3|2]<<16|
(uint64_t)_seed[i<<3|1]<<8|_seed[i<<3];
}
_nseed-=i<<3;
if(_nseed>0){
uint64_t ri;
ri=_seed[i<<3];
for(j=1;j<_nseed;j++)ri|=(uint64_t)_seed[i<<3|j]<<(j<<3);
r[i++]^=ri;
}
x[0]=x[1]=x[2]=x[3]=x[4]=x[5]=x[6]=x[7]=(uint64_t)0x9E3779B97F4A7C13ULL;
for(i=0;i<4;i++)isaac64_mix(x);
for(i=0;i<ISAAC64_SZ;i+=8){
for(j=0;j<8;j++)x[j]+=r[i+j];
isaac64_mix(x);
memcpy(m+i,x,sizeof(x));
}
for(i=0;i<ISAAC64_SZ;i+=8){
for(j=0;j<8;j++)x[j]+=m[i+j];
isaac64_mix(x);
memcpy(m+i,x,sizeof(x));
}
isaac64_update(_ctx);
}
uint64_t isaac64_next_uint64(isaac64_ctx *_ctx){
if(!_ctx->n)isaac64_update(_ctx);
return _ctx->r[--_ctx->n];
}
uint64_t isaac64_next_uint(isaac64_ctx *_ctx,uint64_t _n){
uint64_t r;
uint64_t v;
uint64_t d;
do{
r=isaac64_next_uint64(_ctx);
v=r%_n;
d=r-v;
}
while(((d+_n-1)&ISAAC64_MASK)<d);
return v;
}

View File

@@ -980,6 +980,9 @@ mklev()
struct mkroom *croom;
int ridx;
reseed_random(rn2);
reseed_random(rn2_on_display_rng);
init_mapseen(&u.uz);
if (getbones())
return;
@@ -1007,6 +1010,9 @@ mklev()
entered; g.rooms[].orig_rtype always retains original rtype value */
for (ridx = 0; ridx < SIZE(g.rooms); ridx++)
g.rooms[ridx].orig_rtype = g.rooms[ridx].rtype;
reseed_random(rn2);
reseed_random(rn2_on_display_rng);
}
void

View File

@@ -524,7 +524,7 @@ struct obj *obj; /* missile (or stack providing it) */
* be careful not to use either one after it's been freed.
*/
if (sym)
tmp_at(DISP_FLASH, obj_to_glyph(singleobj));
tmp_at(DISP_FLASH, obj_to_glyph(singleobj, rn2_on_display_rng));
while (range-- > 0) { /* Actually the loop is always exited by break */
g.bhitpos.x += dx;
g.bhitpos.y += dy;

View File

@@ -1957,7 +1957,7 @@ struct monst *mtmp;
#ifdef CLIPPING
cliparound(mtmp->mx, mtmp->my);
#endif
show_glyph(mtmp->mx, mtmp->my, mon_to_glyph(mtmp));
show_glyph(mtmp->mx, mtmp->my, mon_to_glyph(mtmp, rn2));
display_self();
You_feel("aggravated at %s.", noit_mon_nam(mtmp));
display_nhwindow(WIN_MAP, TRUE);

View File

@@ -683,8 +683,9 @@ initoptions_init()
/* set up the command parsing */
reset_commands(TRUE); /* init */
/* initialize the random number generator */
setrandom();
/* initialize the random number generator(s) */
init_random(rn2);
init_random(rn2_on_display_rng);
/* for detection of configfile options specified multiple times */
iflags.opt_booldup = iflags.opt_compdup = (int *) 0;

View File

@@ -381,7 +381,8 @@ char *buf, *monbuf;
buf[0] = monbuf[0] = '\0';
glyph = glyph_at(x, y);
if (u.ux == x && u.uy == y && canspotself()
&& !(iflags.save_uswallow && glyph == mon_to_glyph(u.ustuck))
&& !(iflags.save_uswallow &&
glyph == mon_to_glyph(u.ustuck, rn2_on_display_rng))
&& (!iflags.terrainmode || (iflags.terrainmode & TER_MON) != 0)) {
/* fill in buf[] */
(void) self_lookat(buf);
@@ -435,7 +436,7 @@ char *buf, *monbuf;
} else if (glyph_is_object(glyph)) {
look_at_object(buf, x, y, glyph); /* fill in buf[] */
} else if (glyph_is_trap(glyph)) {
int tnum = what_trap(glyph_to_trap(glyph));
int tnum = what_trap(glyph_to_trap(glyph), rn2_on_display_rng);
/* Trap detection displays a bear trap at locations having
* a trapped door or trapped container or both.
@@ -1487,7 +1488,7 @@ doidtrap()
if (u.dz < 0 ? is_hole(tt) : tt == ROCKTRAP)
break;
}
tt = what_trap(tt);
tt = what_trap(tt, rn2_on_display_rng);
pline("That is %s%s%s.",
an(defsyms[trap_to_defsym(tt)].explanation),
!trap->madeby_u

View File

@@ -902,7 +902,7 @@ boolean FDECL((*allow), (OBJ_P)); /* allow function */
}
any.a_obj = curr;
add_menu(win, obj_to_glyph(curr), &any,
add_menu(win, obj_to_glyph(curr, rn2_on_display_rng), &any,
(qflags & USE_INVLET) ? curr->invlet
: (first && curr->oclass == COIN_CLASS) ? '$' : 0,
def_oc_syms[(int) objects[curr->otyp].oc_class].sym,
@@ -927,7 +927,7 @@ boolean FDECL((*allow), (OBJ_P)); /* allow function */
fake_hero_object = cg.zeroobj;
fake_hero_object.quan = 1L; /* not strictly necessary... */
any.a_obj = &fake_hero_object;
add_menu(win, mon_to_glyph(&g.youmonst), &any,
add_menu(win, mon_to_glyph(&g.youmonst, rn2_on_display_rng), &any,
/* fake inventory letter, no group accelerator */
CONTAINED_SYM, 0, ATR_NONE, an(self_lookat(buf)),
MENU_UNSELECTED);

View File

@@ -2090,13 +2090,18 @@ aligntyp alignment;
if (!Hallucination)
return align_gname(alignment);
/* Count the roles, so that we can pick one at random. */
int rolecount = 0;
while (roles[rolecount].filecode)
rolecount++;
/* The priest may not have initialized god names. If this is the
* case, and we roll priest, we need to try again. */
case, and we roll priest, we need to try again. */
do
which = randrole();
which = rn2_on_display_rng(rolecount);
while (!roles[which].lgod);
switch (rn2(9)) {
switch (rn2_on_display_rng(9)) {
case 0:
case 1:
gnam = roles[which].lgod;
@@ -2111,7 +2116,7 @@ aligntyp alignment;
break;
case 6:
case 7:
gnam = hallu_gods[rn2(sizeof hallu_gods / sizeof *hallu_gods)];
gnam = hallu_gods[rn2_on_display_rng(SIZE(hallu_gods))];
break;
case 8:
gnam = Moloch;

View File

@@ -4,6 +4,74 @@
#include "hack.h"
#ifdef USE_ISAAC64
#include "isaac64.h"
#if 0
static isaac64_ctx rng_state;
#endif
struct rnglist_t {
int FDECL((*fn), (int));
boolean init;
isaac64_ctx rng_state;
};
enum {CORE = 0, DISP};
static struct rnglist_t rnglist[] = {
{rn2, FALSE, {0}}, /* CORE */
{rn2_on_display_rng, FALSE, {0}}, /* DISP */
};
int
whichrng(fn)
int (*fn)(int);
{
int i;
for (i = 0; i < SIZE(rnglist); ++i)
if (rnglist[i].fn == fn)
return i;
return -1;
}
void
init_isaac64(seed, fn)
unsigned long seed;
int FDECL((*fn),(int));
{
unsigned char new_rng_state[sizeof(seed)];
int i, rngindx = whichrng(fn);
if (rngindx < 0)
panic("Bad rng function passed to init_isaac64().");
for (i=0; i<sizeof(seed); i++) {
new_rng_state[i]= (unsigned char)(seed & 0xFF);
seed >>= 8;
}
isaac64_init(&rnglist[rngindx].rng_state, new_rng_state, sizeof(seed));
}
static int
RND(int x)
{
return (isaac64_next_uint64(&rnglist[CORE].rng_state) % x);
}
/* 0 <= rn2(x) < x, but on a different sequence from the "main" rn2;
used in cases where the answer doesn't affect gameplay and we don't
want to give users easy control over the main RNG sequence. */
int
rn2_on_display_rng(x)
register int x;
{
return (isaac64_next_uint64(&rnglist[DISP].rng_state) % x);
}
#else /* USE_ISAAC64 */
/* "Rand()"s definition is determined by [OS]conf.h */
#if defined(LINT) && defined(UNIX) /* rand() is long... */
extern int NDECL(rand);
@@ -16,6 +84,15 @@ extern int NDECL(rand);
#define RND(x) ((int) ((Rand() >> 3) % (x)))
#endif
#endif /* LINT */
int
rn2_on_display_rng(x)
register int x;
{
static unsigned seed = 1;
seed *= 2739110765;
return (int)((seed >> 16) % (unsigned)x);
}
#endif /* USE_ISAAC64 */
/* 0 <= rn2(x) < x */
int

View File

@@ -114,12 +114,12 @@ boolean exclude_cookie;
case 2: /*(might let a bogus input arg sneak thru)*/
case 1:
beginning = (long) g.true_rumor_start;
tidbit = Rand() % g.true_rumor_size;
tidbit = rn2(g.true_rumor_size);
break;
case 0: /* once here, 0 => false rather than "either"*/
case -1:
beginning = (long) g.false_rumor_start;
tidbit = Rand() % g.false_rumor_size;
tidbit = rn2(g.false_rumor_size);
break;
default:
impossible("strange truth value for rumor");
@@ -269,11 +269,13 @@ rumor_check()
}
}
/* Gets a random line of text from file 'fname', and returns it. */
/* Gets a random line of text from file 'fname', and returns it.
rng is the random number generator to use, and should act like rn2 does. */
char *
get_rnd_text(fname, buf)
get_rnd_text(fname, buf, rng)
const char *fname;
char *buf;
int FDECL((*rng), (int));
{
dlb *fh;
@@ -294,7 +296,7 @@ char *buf;
(void) dlb_fseek(fh, 0L, SEEK_END);
endtxt = dlb_ftell(fh);
sizetxt = endtxt - starttxt;
tidbit = Rand() % sizetxt;
tidbit = rng(sizetxt);
(void) dlb_fseek(fh, starttxt + tidbit, SEEK_SET);
(void) dlb_fgets(line, sizeof line, fh);

View File

@@ -1801,7 +1801,7 @@ int style;
delaycnt = 1;
if (!cansee(g.bhitpos.x, g.bhitpos.y))
curs_on_u();
tmp_at(DISP_FLASH, obj_to_glyph(singleobj));
tmp_at(DISP_FLASH, obj_to_glyph(singleobj, rn2_on_display_rng));
tmp_at(g.bhitpos.x, g.bhitpos.y);
}
/* Mark a spot to place object in bones files to prevent

View File

@@ -2018,7 +2018,7 @@ struct monst *mdef;
{
if (!Invisible) {
map_location(u.ux, u.uy, TRUE);
tmp_at(DISP_ALWAYS, mon_to_glyph(&g.youmonst));
tmp_at(DISP_ALWAYS, mon_to_glyph(&g.youmonst, rn2_on_display_rng));
tmp_at(mdef->mx, mdef->my);
}
You("engulf %s!", mon_nam(mdef));

View File

@@ -457,13 +457,14 @@ boolean use_detection_glyph;
struct wseg *curr = wtails[worm->wormno];
/* if (!mtmp->wormno) return; bullet proofing */
int what_tail = what_mon(PM_LONG_WORM_TAIL, newsym_rn2);
while (curr != wheads[worm->wormno]) {
num = use_detection_glyph
? detected_monnum_to_glyph(what_mon(PM_LONG_WORM_TAIL))
? detected_monnum_to_glyph(what_tail)
: (worm->mtame
? petnum_to_glyph(what_mon(PM_LONG_WORM_TAIL))
: monnum_to_glyph(what_mon(PM_LONG_WORM_TAIL)));
? petnum_to_glyph(what_tail)
: monnum_to_glyph(what_tail));
show_glyph(curr->wx, curr->wy, num);
curr = curr->nseg;
}

View File

@@ -1480,7 +1480,7 @@ int id;
/* now change it into something laid by the hero */
while (tryct--) {
mnum = can_be_hatched(random_monster());
mnum = can_be_hatched(random_monster(rn2));
if (mnum != NON_PM && !dead_species(mnum, TRUE)) {
otmp->spe = 1; /* laid by hero */
set_corpsenm(otmp, mnum); /* also sets hatch timer */
@@ -3192,9 +3192,9 @@ struct obj **pobj; /* object tossed/used, set to NULL
} else if (weapon == THROWN_TETHERED_WEAPON && obj) {
tethered_weapon = TRUE;
weapon = THROWN_WEAPON; /* simplify if's that follow below */
tmp_at(DISP_TETHER, obj_to_glyph(obj));
tmp_at(DISP_TETHER, obj_to_glyph(obj, rn2_on_display_rng));
} else if (weapon != ZAPPED_WAND && weapon != INVIS_BEAM)
tmp_at(DISP_FLASH, obj_to_glyph(obj));
tmp_at(DISP_FLASH, obj_to_glyph(obj, rn2_on_display_rng));
while (range-- > 0) {
int x, y;