Merge branch 'alex-and-isaac' into NetHack-3.6.2-beta01

This commit is contained in:
nhmall
2019-01-29 07:20:17 -05:00
50 changed files with 778 additions and 205 deletions
+1
View File
@@ -556,6 +556,7 @@ typedef unsigned char uchar;
#endif #endif
#define USE_ISAAC64 /* Use cross-plattform, bundled RNG */
/* End of Section 4 */ /* End of Section 4 */
+1
View File
@@ -220,6 +220,7 @@ E NEARDATA boolean mrg_to_wielded;
E NEARDATA boolean defer_see_monsters; E NEARDATA boolean defer_see_monsters;
E NEARDATA boolean in_steed_dismounting; E NEARDATA boolean in_steed_dismounting;
E NEARDATA boolean has_strong_rngseed;
E const int shield_static[]; E const int shield_static[];
+41 -28
View File
@@ -146,9 +146,9 @@
* *
* Respectively return a random monster, object, or trap number. * Respectively return a random monster, object, or trap number.
*/ */
#define random_monster() rn2(NUMMONS) #define random_monster(rng) rng(NUMMONS)
#define random_object() rn1(NUM_OBJECTS - 1, 1) #define random_object(rng) (rng(NUM_OBJECTS - 1) + 1)
#define random_trap() rn1(TRAPNUM - 1, 1) #define random_trap(rng) (rng(TRAPNUM - 1) + 1)
/* /*
* what_obj() * what_obj()
@@ -156,11 +156,23 @@
* what_trap() * what_trap()
* *
* If hallucinating, choose a random object/monster, otherwise, use the one * If hallucinating, choose a random object/monster, otherwise, use the one
* given. * given. Use the given rng to handle hallucination.
*/ */
#define what_obj(obj) (Hallucination ? random_object() : obj) #define what_obj(obj, rng) (Hallucination ? random_object(rng) : obj)
#define what_mon(mon) (Hallucination ? random_monster() : mon) #define what_mon(mon, rng) (Hallucination ? random_monster(rng) : mon)
#define what_trap(trp) (Hallucination ? random_trap() : trp) #define what_trap(trp, rng) (Hallucination ? random_trap(rng) : trp)
/*
* newsym_rn2
*
* An appropriate random number generator for use with newsym(), when
* randomness is needed there. This is currently hardcoded as
* rn2_on_display_rng, but is futureproofed for cases where we might
* want to prevent display-random objects entering the character's
* memory (this isn't important at present but may be if we need
* reproducible gameplay for some reason).
*/
#define newsym_rn2 rn2_on_display_rng
/* /*
* covers_objects() * covers_objects()
@@ -196,9 +208,10 @@
* Display the hero. It is assumed that all checks necessary to determine * Display the hero. It is assumed that all checks necessary to determine
* _if_ the hero can be seen have already been done. * _if_ the hero can be seen have already been done.
*/ */
#define maybe_display_usteed(otherwise_self) \ #define maybe_display_usteed(otherwise_self) \
((u.usteed && mon_visible(u.usteed)) ? ridden_mon_to_glyph(u.usteed) \ ((u.usteed && mon_visible(u.usteed)) \
: (otherwise_self)) ? ridden_mon_to_glyph(u.usteed, rn2_on_display_rng) \
: (otherwise_self))
#define display_self() \ #define display_self() \
show_glyph(u.ux, u.uy, \ show_glyph(u.ux, u.uy, \
@@ -282,27 +295,27 @@
#define GLYPH_INVISIBLE GLYPH_INVIS_OFF #define GLYPH_INVISIBLE GLYPH_INVIS_OFF
#define warning_to_glyph(mwarnlev) ((mwarnlev) + GLYPH_WARNING_OFF) #define warning_to_glyph(mwarnlev) ((mwarnlev) + GLYPH_WARNING_OFF)
#define mon_to_glyph(mon) \ #define mon_to_glyph(mon, rng) \
((int) what_mon(monsndx((mon)->data)) + GLYPH_MON_OFF) ((int) what_mon(monsndx((mon)->data), rng) + GLYPH_MON_OFF)
#define detected_mon_to_glyph(mon) \ #define detected_mon_to_glyph(mon, rng) \
((int) what_mon(monsndx((mon)->data)) + GLYPH_DETECT_OFF) ((int) what_mon(monsndx((mon)->data), rng) + GLYPH_DETECT_OFF)
#define ridden_mon_to_glyph(mon) \ #define ridden_mon_to_glyph(mon, rng) \
((int) what_mon(monsndx((mon)->data)) + GLYPH_RIDDEN_OFF) ((int) what_mon(monsndx((mon)->data), rng) + GLYPH_RIDDEN_OFF)
#define pet_to_glyph(mon) \ #define pet_to_glyph(mon, rng) \
((int) what_mon(monsndx((mon)->data)) + GLYPH_PET_OFF) ((int) what_mon(monsndx((mon)->data), rng) + GLYPH_PET_OFF)
/* This has the unfortunate side effect of needing a global variable */ /* This has the unfortunate side effect of needing a global variable */
/* to store a result. 'otg_temp' is defined and declared in decl.{ch}. */ /* to store a result. 'otg_temp' is defined and declared in decl.{ch}. */
#define random_obj_to_glyph() \ #define random_obj_to_glyph(rng) \
((otg_temp = random_object()) == CORPSE \ ((otg_temp = random_object(rng)) == CORPSE \
? random_monster() + GLYPH_BODY_OFF \ ? random_monster(rng) + GLYPH_BODY_OFF \
: otg_temp + GLYPH_OBJ_OFF) : otg_temp + GLYPH_OBJ_OFF)
#define obj_to_glyph(obj) \ #define obj_to_glyph(obj, rng) \
(((obj)->otyp == STATUE) \ (((obj)->otyp == STATUE) \
? statue_to_glyph(obj) \ ? statue_to_glyph(obj, rng) \
: Hallucination \ : Hallucination \
? random_obj_to_glyph() \ ? random_obj_to_glyph(rng) \
: ((obj)->otyp == CORPSE) \ : ((obj)->otyp == CORPSE) \
? (int) (obj)->corpsenm + GLYPH_BODY_OFF \ ? (int) (obj)->corpsenm + GLYPH_BODY_OFF \
: (int) (obj)->otyp + GLYPH_OBJ_OFF) : (int) (obj)->otyp + GLYPH_OBJ_OFF)
@@ -310,16 +323,16 @@
/* MRKR: Statues now have glyphs corresponding to the monster they */ /* MRKR: Statues now have glyphs corresponding to the monster they */
/* represent and look like monsters when you are hallucinating. */ /* represent and look like monsters when you are hallucinating. */
#define statue_to_glyph(obj) \ #define statue_to_glyph(obj, rng) \
(Hallucination ? random_monster() + GLYPH_MON_OFF \ (Hallucination ? random_monster(rng) + GLYPH_MON_OFF \
: (int) (obj)->corpsenm + GLYPH_STATUE_OFF) : (int) (obj)->corpsenm + GLYPH_STATUE_OFF)
#define cmap_to_glyph(cmap_idx) ((int) (cmap_idx) + GLYPH_CMAP_OFF) #define cmap_to_glyph(cmap_idx) ((int) (cmap_idx) + GLYPH_CMAP_OFF)
#define explosion_to_glyph(expltype, idx) \ #define explosion_to_glyph(expltype, idx) \
((((expltype) * MAXEXPCHARS) + ((idx) - S_explode1)) + GLYPH_EXPLODE_OFF) ((((expltype) * MAXEXPCHARS) + ((idx) - S_explode1)) + GLYPH_EXPLODE_OFF)
#define trap_to_glyph(trap) \ #define trap_to_glyph(trap, rng) \
cmap_to_glyph(trap_to_defsym(what_trap((trap)->ttyp))) cmap_to_glyph(trap_to_defsym(what_trap((trap)->ttyp, rng)))
/* Not affected by hallucination. Gives a generic body for CORPSE */ /* Not affected by hallucination. Gives a generic body for CORPSE */
/* MRKR: ...and the generic statue */ /* MRKR: ...and the generic statue */
+8 -2
View File
@@ -925,7 +925,8 @@ E char *FDECL(strstri, (const char *, const char *));
#endif #endif
E boolean E boolean
FDECL(fuzzymatch, (const char *, const char *, const char *, BOOLEAN_P)); FDECL(fuzzymatch, (const char *, const char *, const char *, BOOLEAN_P));
E void NDECL(setrandom); E void FDECL(init_random, (int FDECL((*fn), (int))));
E void FDECL(reseed_random, (int FDECL((*fn), (int))));
E time_t NDECL(getnow); E time_t NDECL(getnow);
E int NDECL(getyear); E int NDECL(getyear);
#if 0 #if 0
@@ -2103,7 +2104,12 @@ E void FDECL(genl_outrip, (winid, int, time_t));
/* ### rnd.c ### */ /* ### rnd.c ### */
#ifdef USE_ISAAC64
E void FDECL(init_isaac64, (unsigned long, int FDECL((*fn), (int))));
E long NDECL(nhrand);
#endif
E int FDECL(rn2, (int)); E int FDECL(rn2, (int));
E int FDECL(rn2_on_display_rng, (int));
E int FDECL(rnl, (int)); E int FDECL(rnl, (int));
E int FDECL(rnd, (int)); E int FDECL(rnd, (int));
E int FDECL(d, (int, int)); E int FDECL(d, (int, int));
@@ -2148,7 +2154,7 @@ E const char *NDECL(Goodbye);
/* ### rumors.c ### */ /* ### rumors.c ### */
E char *FDECL(getrumor, (int, char *, BOOLEAN_P)); E char *FDECL(getrumor, (int, char *, BOOLEAN_P));
E char *FDECL(get_rnd_text, (const char *, char *)); E char *FDECL(get_rnd_text, (const char *, char *, int FDECL((*), (int))));
E void FDECL(outrumor, (int, int)); E void FDECL(outrumor, (int, int));
E void FDECL(outoracle, (BOOLEAN_P, BOOLEAN_P)); E void FDECL(outoracle, (BOOLEAN_P, BOOLEAN_P));
E void FDECL(save_oracles, (int, int)); E void FDECL(save_oracles, (int, int));
+35 -23
View File
@@ -7,35 +7,47 @@
#ifndef INTEGER_H #ifndef INTEGER_H
#define INTEGER_H #define INTEGER_H
#if defined(__STDC__) && __STDC__ >= 199101L #if defined(__STDC__) && __STDC_VERSION__ >= 199101L
/* The compiler claims to conform to C99. Use stdint.h */ /* The compiler claims to conform to C99. Use stdint.h */
#include <stdint.h> #include <stdint.h>
#define SKIP_STDINT_WORKAROUND
#else
# if defined(HAS_STDINT_H)
/* Some compilers have stdint.h but don't conform to all of C99. */
#include <stdint.h>
#define SKIP_STDINT_WORKAROUND
# endif
#endif
#ifndef SKIP_STDINT_WORKAROUND /* !C99 */
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short uint16_t;
#if defined(__WATCOMC__) && !defined(__386__)
/* Open Watcom providing a 16 bit build for MS-DOS or OS/2 */
/* int is 16 bits; use long for 32 bits */
typedef long int32_t;
typedef unsigned long uint32_t;
#else
/* Otherwise, assume either a 32- or 64-bit compiler */
/* long may be 64 bits; use int for 32 bits */
typedef int int32_t;
typedef unsigned int uint32_t;
#endif
typedef long long int64_t;
typedef unsigned long long uint64_t;
#endif /* !C99 */
/* Provide uint8, int16, uint16, int32, uint32, int64 and uint64 */
typedef uint8_t uint8; typedef uint8_t uint8;
typedef int16_t int16; typedef int16_t int16;
typedef uint16_t uint16; typedef uint16_t uint16;
typedef int32_t int32; typedef int32_t int32;
typedef uint32_t uint32; typedef uint32_t uint32;
typedef int64_t int64;
#else /* !C99 */ typedef uint64_t uint64;
/* Provide uint8, int16, uint16, int32 and uint32 */
typedef unsigned char uint8;
typedef short int16;
typedef unsigned short uint16;
#if defined(__WATCOMC__) && !defined(__386__)
/* Open Watcom providing a 16 bit build for MS-DOS or OS/2 */
/* int is 16 bits; use long for 32 bits */
typedef long int32;
typedef unsigned long uint32;
#else
/* Otherwise, assume either a 32- or 64-bit compiler */
/* long may be 64 bits; use int for 32 bits */
typedef int int32;
typedef unsigned int uint32;
#endif
#endif /* !C99 */
#endif /* INTEGER_H */ #endif /* INTEGER_H */
+89
View File
@@ -0,0 +1,89 @@
/* CC0 (Public domain) - see http://creativecommons.org/publicdomain/zero/1.0/ for details */
#if !defined(_isaac64_H)
# define _isaac64_H (1)
# include <integer.h>
typedef struct isaac64_ctx isaac64_ctx;
#define ISAAC64_SZ_LOG (8)
#define ISAAC64_SZ (1<<ISAAC64_SZ_LOG)
#define ISAAC64_SEED_SZ_MAX (ISAAC64_SZ<<3)
/*ISAAC is the most advanced of a series of pseudo-random number generators
designed by Robert J. Jenkins Jr. in 1996.
http://www.burtleburtle.net/bob/rand/isaac.html
This is the 64-bit version.
To quote:
ISAAC-64 generates a different sequence than ISAAC, but it uses the same
principles.
It uses 64-bit arithmetic.
It generates a 64-bit result every 19 instructions.
All cycles are at least 2**72 values, and the average cycle length is
2**16583.*/
struct isaac64_ctx{
unsigned n;
uint64_t r[ISAAC64_SZ];
uint64_t m[ISAAC64_SZ];
uint64_t a;
uint64_t b;
uint64_t c;
};
/**
* isaac64_init - Initialize an instance of the ISAAC64 random number generator.
* @_ctx: The ISAAC64 instance to initialize.
* @_seed: The specified seed bytes.
* This may be NULL if _nseed is less than or equal to zero.
* @_nseed: The number of bytes to use for the seed.
* If this is greater than ISAAC64_SEED_SZ_MAX, the extra bytes are
* ignored.
*/
void isaac64_init(isaac64_ctx *_ctx,const unsigned char *_seed,int _nseed);
/**
* isaac64_reseed - Mix a new batch of entropy into the current state.
* To reset ISAAC64 to a known state, call isaac64_init() again instead.
* @_ctx: The instance to reseed.
* @_seed: The specified seed bytes.
* This may be NULL if _nseed is zero.
* @_nseed: The number of bytes to use for the seed.
* If this is greater than ISAAC64_SEED_SZ_MAX, the extra bytes are
* ignored.
*/
void isaac64_reseed(isaac64_ctx *_ctx,const unsigned char *_seed,int _nseed);
/**
* isaac64_next_uint64 - Return the next random 64-bit value.
* @_ctx: The ISAAC64 instance to generate the value with.
*/
uint64_t isaac64_next_uint64(isaac64_ctx *_ctx);
/**
* isaac64_next_uint - Uniform random integer less than the given value.
* @_ctx: The ISAAC64 instance to generate the value with.
* @_n: The upper bound on the range of numbers returned (not inclusive).
* This must be greater than zero and less than 2**64.
* To return integers in the full range 0...2**64-1, use
* isaac64_next_uint64() instead.
* Return: An integer uniformly distributed between 0 and _n-1 (inclusive).
*/
uint64_t isaac64_next_uint(isaac64_ctx *_ctx,uint64_t _n);
/**
* isaac64_next_float - Uniform random float in the range [0,1).
* @_ctx: The ISAAC64 instance to generate the value with.
* Returns a high-quality float uniformly distributed between 0 (inclusive)
* and 1 (exclusive).
* All of the float's mantissa bits are random, e.g., the least significant bit
* may still be non-zero even if the value is less than 0.5, and any
* representable float in the range [0,1) has a chance to be returned, though
* values very close to zero become increasingly unlikely.
* To generate cheaper float values that do not have these properties, use
* ldexpf((float)isaac64_next_uint64(_ctx),-64);
*/
#endif
+15 -8
View File
@@ -7,7 +7,6 @@
/* #define SHELL */ /* nt use of pcsys routines caused a hang */ /* #define SHELL */ /* nt use of pcsys routines caused a hang */
#define RANDOM /* have Berkeley random(3) */
#define TEXTCOLOR /* Color text */ #define TEXTCOLOR /* Color text */
#define EXEPATH /* Allow .exe location to be used as HACKDIR */ #define EXEPATH /* Allow .exe location to be used as HACKDIR */
@@ -25,8 +24,7 @@
game */ game */
#define SYSCF /* Use a global configuration */ #define SYSCF /* Use a global configuration */
#define SYSCF_FILE "sysconf" /* Use a file to hold the SYSCF configuration \ #define SYSCF_FILE "sysconf" /* Use a file to hold the SYSCF configuration */
*/
#define DUMPLOG /* Enable dumplog files */ #define DUMPLOG /* Enable dumplog files */
/*#define DUMPLOG_FILE "nethack-%n-%d.log"*/ /*#define DUMPLOG_FILE "nethack-%n-%d.log"*/
@@ -35,9 +33,8 @@
#define USER_SOUNDS #define USER_SOUNDS
/*#define CHANGE_COLOR*/ /* allow palette changes */ /*#define CHANGE_COLOR*/ /* allow palette changes */
#define SELECTSAVED /* Provide menu of saved games to choose from at start \ #define SELECTSAVED /* Provide menu of saved games to choose from at start */
*/
/* /*
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* The remaining code shouldn't need modification. * The remaining code shouldn't need modification.
@@ -131,6 +128,9 @@ extern void FDECL(interject, (int));
/* suppress a warning in cppregex.cpp */ /* suppress a warning in cppregex.cpp */
#pragma warning(disable : 4101) /* unreferenced local variable */ #pragma warning(disable : 4101) /* unreferenced local variable */
#endif #endif
#ifndef HAS_STDINT_H
#define HAS_STDINT_H /* force include of stdint.h in integer.h */
#endif
#endif /* _MSC_VER */ #endif /* _MSC_VER */
/* The following is needed for prototypes of certain functions */ /* The following is needed for prototypes of certain functions */
@@ -180,10 +180,17 @@ extern void FDECL(interject, (int));
#include <time.h> #include <time.h>
#define USE_STDARG #define USE_STDARG
#ifdef RANDOM
/* Use the high quality random number routines. */ /* Use the high quality random number routines. */
#define Rand() random() #ifdef USE_ISAAC64
#undef RANDOM
#else #else
#define RANDOM
#define Rand() random()
#endif
/* Fall back to C's if nothing else, but this really isn't acceptable */
#if !defined(USE_ISAAC64) && !defined(RANDOM)
#define Rand() rand() #define Rand() rand()
#endif #endif
+6 -5
View File
@@ -78,11 +78,12 @@
#include <time.h> #include <time.h>
/* the high quality random number routines */ /* the high quality random number routines */
#ifndef USE_ISAAC64
#ifdef RANDOM # ifdef RANDOM
#define Rand() random() # define Rand() random()
#else # else
#define Rand() rand() # define Rand() rand()
# endif
#endif #endif
/* file creation mask */ /* file creation mask */
+7 -5
View File
@@ -236,11 +236,13 @@
#include <time.h> #include <time.h>
#endif #endif
#ifdef RANDOM /* the high quality random number routines */
/* Use the high quality random number routines. */ #ifndef USE_ISAAC64
#define Rand() random() # ifdef RANDOM
#else # define Rand() random()
#define Rand() rand() # else
# define Rand() rand()
# endif
#endif #endif
#ifndef TOS #ifndef TOS
+20 -4
View File
@@ -347,11 +347,14 @@
#endif #endif
/* Use the high quality random number routines. */ /* Use the high quality random number routines. */
#if defined(BSD) || defined(LINUX) || defined(ULTRIX) || defined(CYGWIN32) \ /* the high quality random number routines */
#ifndef USE_ISAAC64
# if defined(BSD) || defined(LINUX) || defined(ULTRIX) || defined(CYGWIN32) \
|| defined(RANDOM) || defined(__APPLE__) || defined(RANDOM) || defined(__APPLE__)
#define Rand() random() # define Rand() random()
#else # else
#define Rand() lrand48() # define Rand() lrand48()
# endif
#endif #endif
#ifdef TIMED_DELAY #ifdef TIMED_DELAY
@@ -408,5 +411,18 @@
# define RUNTIME_PASTEBUF_SUPPORT # define RUNTIME_PASTEBUF_SUPPORT
#endif #endif
/*
* /dev/random is blocking on Linux, so there we default to /dev/urandom which
* should still be good enough.
* BSD systems usually have /dev/random that is supposed to be used.
*/
#ifdef LINUX
# define DEV_RANDOM "/dev/urandom"
#else
# ifdef BSD
# define DEV_RANDOM "/dev/random"
# endif
#endif
#endif /* UNIXCONF_H */ #endif /* UNIXCONF_H */
#endif /* UNIX */ #endif /* UNIX */
+10 -8
View File
@@ -243,17 +243,19 @@ typedef __mode_t mode_t;
#define rindex strrchr #define rindex strrchr
/* Use the high quality random number routines. */ /* Use the high quality random number routines. */
#if defined(RANDOM) #ifndef USE_ISAAC64
#define Rand() random() # if defined(RANDOM)
# define Rand() random()
/* VMS V7 adds these entry points to DECC$SHR; stick with the nethack-supplied /* VMS V7 adds these entry points to DECC$SHR; stick with the nethack-supplied
code to avoid having to deal with version-specific conditionalized builds code to avoid having to deal with version-specific conditionalized builds
*/ */
#define random nh_random # define random nh_random
#define srandom nh_srandom # define srandom nh_srandom
#define initstate nh_initstate # define initstate nh_initstate
#define setstate nh_setstate # define setstate nh_setstate
#else # else
#define Rand() rand() # define Rand() rand()
# endif
#endif #endif
#ifndef __GNUC__ #ifndef __GNUC__
+7 -4
View File
@@ -141,11 +141,14 @@
#define index strchr #define index strchr
#define rindex strrchr #define rindex strrchr
#define USE_STDARG #define USE_STDARG
#ifdef RANDOM
/* Use the high quality random number routines. */ /* Use the high quality random number routines. */
#define Rand() random() #ifndef USE_ISAAC64
#else # ifdef RANDOM
#define Rand() rand() # define Rand() random()
# else
# define Rand() rand()
# endif
#endif #endif
#define FCMASK 0660 /* file creation mask */ #define FCMASK 0660 /* file creation mask */
+7 -6
View File
@@ -241,7 +241,7 @@ int rx, ry, *resp;
int visglyph, corpseglyph; int visglyph, corpseglyph;
visglyph = glyph_at(rx, ry); visglyph = glyph_at(rx, ry);
corpseglyph = obj_to_glyph(corpse); corpseglyph = obj_to_glyph(corpse, rn2);
if (Blind && (visglyph != corpseglyph)) if (Blind && (visglyph != corpseglyph))
map_object(corpse, TRUE); map_object(corpse, TRUE);
@@ -2501,7 +2501,7 @@ struct obj *otmp;
ttyp = (otmp->otyp == LAND_MINE) ? LANDMINE : BEAR_TRAP; ttyp = (otmp->otyp == LAND_MINE) ? LANDMINE : BEAR_TRAP;
if (otmp == trapinfo.tobj && u.ux == trapinfo.tx && u.uy == trapinfo.ty) { if (otmp == trapinfo.tobj && u.ux == trapinfo.tx && u.uy == trapinfo.ty) {
You("resume setting %s%s.", shk_your(buf, otmp), 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); set_occupation(set_trap, occutext, 0);
return; return;
} }
@@ -2526,7 +2526,8 @@ struct obj *otmp;
chance = (rnl(10) > 5); chance = (rnl(10) > 5);
You("aren't very skilled at reaching from %s.", mon_nam(u.usteed)); You("aren't very skilled at reaching from %s.", mon_nam(u.usteed));
Sprintf(buf, "Continue your attempt to set %s?", 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 (yn(buf) == 'y') {
if (chance) { if (chance) {
switch (ttyp) { switch (ttyp) {
@@ -2537,7 +2538,7 @@ struct obj *otmp;
case BEAR_TRAP: /* drop it without arming it */ case BEAR_TRAP: /* drop it without arming it */
reset_trapset(); reset_trapset();
You("drop %s!", You("drop %s!",
the(defsyms[trap_to_defsym(what_trap(ttyp))] the(defsyms[trap_to_defsym(what_trap(ttyp, rn2))]
.explanation)); .explanation));
dropx(otmp); dropx(otmp);
return; return;
@@ -2549,7 +2550,7 @@ struct obj *otmp;
} }
} }
You("begin setting %s%s.", shk_your(buf, 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); set_occupation(set_trap, occutext, 0);
return; return;
} }
@@ -2582,7 +2583,7 @@ set_trap()
} }
if (!trapinfo.force_bungle) if (!trapinfo.force_bungle)
You("finish arming %s.", 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)) if (((otmp->cursed || Fumbling) && (rnl(10) > 5))
|| trapinfo.force_bungle) || trapinfo.force_bungle)
dotrap(ttmp, dotrap(ttmp,
+1
View File
@@ -120,6 +120,7 @@ NEARDATA boolean mrg_to_wielded = FALSE;
/* weapon picked is merged with wielded one */ /* weapon picked is merged with wielded one */
NEARDATA boolean in_steed_dismounting = FALSE; NEARDATA boolean in_steed_dismounting = FALSE;
NEARDATA boolean has_strong_rngseed = FALSE;
NEARDATA coord bhitpos = DUMMY; NEARDATA coord bhitpos = DUMMY;
NEARDATA coord doors[DOORMAX] = { DUMMY }; NEARDATA coord doors[DOORMAX] = { DUMMY };
+17 -9
View File
@@ -78,10 +78,12 @@ struct monst *mtmp;
boolean showtail; boolean showtail;
{ {
if (def_monsyms[(int) mtmp->data->mlet].sym == ' ') 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, 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]) if (showtail && mtmp->data == &mons[PM_LONG_WORM])
detect_wsegs(mtmp, 0); detect_wsegs(mtmp, 0);
@@ -867,10 +869,10 @@ int src_cursed;
obj.ox = x; obj.ox = x;
obj.oy = y; 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) obj.quan = (long) ((obj.otyp == GOLD_PIECE) ? rnd(10)
: objects[obj.otyp].oc_merge ? rnd(2) : 1); : 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); map_object(&obj, 1);
} else if (trap) { } else if (trap) {
map_trap(trap, 1); map_trap(trap, 1);
@@ -1591,14 +1593,20 @@ void
find_trap(trap) find_trap(trap)
struct trap *trap; struct trap *trap;
{ {
int tt = what_trap(trap->ttyp); int tt = what_trap(trap->ttyp, rn2);
boolean cleared = FALSE; boolean cleared = FALSE;
trap->tseen = 1; trap->tseen = 1;
exercise(A_WIS, TRUE); exercise(A_WIS, TRUE);
feel_newsym(trap->tx, trap->ty); 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 */ /* There's too much clutter to see your find otherwise */
cls(); cls();
map_trap(trap, 1); map_trap(trap, 1);
@@ -1832,7 +1840,7 @@ int default_glyph, which_subset;
an object, replacing any object or trap at its spot) */ an object, replacing any object or trap at its spot) */
glyph = !swallowed ? glyph_at(x, y) : levl_glyph; glyph = !swallowed ? glyph_at(x, y) : levl_glyph;
if (keep_mons && x == u.ux && y == u.uy && swallowed) 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) else if (((glyph_is_monster(glyph)
|| glyph_is_warning(glyph)) && !keep_mons) || glyph_is_warning(glyph)) && !keep_mons)
|| glyph_is_swallow(glyph)) || glyph_is_swallow(glyph))
@@ -1841,7 +1849,7 @@ int default_glyph, which_subset;
|| glyph_is_invisible(glyph)) || glyph_is_invisible(glyph))
&& keep_traps && !covers_traps(x, y)) { && keep_traps && !covers_traps(x, y)) {
if ((t = t_at(x, y)) != 0 && t->tseen) 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) if ((glyph_is_object(glyph) && !keep_objs)
|| (glyph_is_trap(glyph) && !keep_traps) || (glyph_is_trap(glyph) && !keep_traps)
+18 -13
View File
@@ -222,7 +222,7 @@ register struct trap *trap;
register int show; register int show;
{ {
register int x = trap->tx, y = trap->ty; 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 (level.flags.hero_memory) if (level.flags.hero_memory)
levl[x][y].glyph = glyph; levl[x][y].glyph = glyph;
@@ -242,14 +242,14 @@ register struct obj *obj;
register int show; register int show;
{ {
register int x = obj->ox, y = obj->oy; 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 (level.flags.hero_memory) { if (level.flags.hero_memory) {
/* MRKR: While hallucinating, statues are seen as random monsters */ /* MRKR: While hallucinating, statues are seen as random monsters */
/* but remembered as random objects. */ /* but remembered as random objects. */
if (Hallucination && obj->otyp == STATUE) { if (Hallucination && obj->otyp == STATUE) {
levl[x][y].glyph = random_obj_to_glyph(); levl[x][y].glyph = random_obj_to_glyph(newsym_rn2);
} else { } else {
levl[x][y].glyph = glyph; levl[x][y].glyph = glyph;
} }
@@ -394,7 +394,7 @@ xchar worm_tail; /* mon is actually a worm tail */
(int) mon->m_ap_type); (int) mon->m_ap_type);
/*FALLTHRU*/ /*FALLTHRU*/
case M_AP_NOTHING: case M_AP_NOTHING:
show_glyph(x, y, mon_to_glyph(mon)); show_glyph(x, y, mon_to_glyph(mon, newsym_rn2));
break; break;
case M_AP_FURNITURE: { case M_AP_FURNITURE: {
@@ -434,7 +434,8 @@ xchar worm_tail; /* mon is actually a worm tail */
case M_AP_MONSTER: case M_AP_MONSTER:
show_glyph(x, y, 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; break;
} }
} }
@@ -456,17 +457,19 @@ xchar worm_tail; /* mon is actually a worm tail */
if (worm_tail) if (worm_tail)
num = petnum_to_glyph(PM_LONG_WORM_TAIL); num = petnum_to_glyph(PM_LONG_WORM_TAIL);
else else
num = pet_to_glyph(mon); num = pet_to_glyph(mon, rn2_on_display_rng);
} else if (sightflags == DETECTED) { } else if (sightflags == DETECTED) {
if (worm_tail) 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 else
num = detected_mon_to_glyph(mon); num = detected_mon_to_glyph(mon, rn2_on_display_rng);
} else { } else {
if (worm_tail) 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 else
num = mon_to_glyph(mon); num = mon_to_glyph(mon, rn2_on_display_rng);
} }
show_glyph(x, y, num); show_glyph(x, y, num);
} }
@@ -489,10 +492,11 @@ register struct monst *mon;
int glyph; int glyph;
if (mon_warning(mon)) { 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); glyph = warning_to_glyph(wl);
} else if (MATCH_WARN_OF_MON(mon)) { } else if (MATCH_WARN_OF_MON(mon)) {
glyph = mon_to_glyph(mon); glyph = mon_to_glyph(mon, rn2_on_display_rng);
} else { } else {
impossible("display_warning did not match warning type?"); impossible("display_warning did not match warning type?");
return; return;
@@ -1751,7 +1755,8 @@ int loc;
impossible("swallow_to_glyph: bad swallow location"); impossible("swallow_to_glyph: bad swallow location");
loc = S_sw_br; 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;
} }
/* /*
+2
View File
@@ -1420,6 +1420,8 @@ boolean at_stairs, falling, portal;
/* we'll reach here if running in wizard mode */ /* we'll reach here if running in wizard mode */
error("Cannot continue this game."); error("Cannot continue this game.");
} }
reseed_random(rn2);
reseed_random(rn2_on_display_rng);
minit(); /* ZEROCOMP */ minit(); /* ZEROCOMP */
getlev(fd, hackpid, new_ledger, FALSE); getlev(fd, hackpid, new_ledger, FALSE);
(void) nhclose(fd); (void) nhclose(fd);
+12 -7
View File
@@ -1538,8 +1538,12 @@ namefloorobj()
unames[0] = ((Upolyd ? u.mfemale : flags.female) && urole.name.f) unames[0] = ((Upolyd ? u.mfemale : flags.female) && urole.name.f)
? urole.name.f ? urole.name.f
: urole.name.m; : urole.name.m;
/* random rank title for hero's role */ /* random rank title for hero's role
unames[1] = rank_of(rnd(30), Role_switch, flags.female);
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 */ /* random fake monster */
unames[2] = bogusmon(tmpbuf, (char *) 0); unames[2] = bogusmon(tmpbuf, (char *) 0);
/* increased chance for fake monster */ /* increased chance for fake monster */
@@ -1550,7 +1554,7 @@ namefloorobj()
unames[5] = "Wibbly Wobbly"; unames[5] = "Wibbly Wobbly";
pline("%s %s to call you \"%s.\"", pline("%s %s to call you \"%s.\"",
The(buf), use_plural ? "decide" : "decides", The(buf), use_plural ? "decide" : "decides",
unames[rn2(SIZE(unames))]); unames[rn2_on_display_rng(SIZE(unames))]);
} else if (!objtyp_is_callable(obj->otyp)) { } else if (!objtyp_is_callable(obj->otyp)) {
pline("%s %s can't be assigned a type name.", pline("%s %s can't be assigned a type name.",
use_plural ? "Those" : "That", buf); use_plural ? "Those" : "That", buf);
@@ -1930,7 +1934,7 @@ char *buf, *code;
{ {
char *mname = buf; char *mname = buf;
get_rnd_text(BOGUSMONFILE, buf); get_rnd_text(BOGUSMONFILE, buf, rn2_on_display_rng);
/* strip prefix if present */ /* strip prefix if present */
if (!letter(*mname)) { if (!letter(*mname)) {
if (code) if (code)
@@ -1957,7 +1961,7 @@ char *code;
*code = '\0'; *code = '\0';
do { 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 } while (name < SPECIAL_PM
&& (type_is_pname(&mons[name]) || (mons[name].geno & G_NOGEN))); && (type_is_pname(&mons[name]) || (mons[name].geno & G_NOGEN)));
@@ -2013,8 +2017,9 @@ const char *
hcolor(colorpref) hcolor(colorpref)
const char *colorpref; const char *colorpref;
{ {
return (Hallucination || !colorpref) ? hcolors[rn2(SIZE(hcolors))] return (Hallucination || !colorpref)
: colorpref; ? hcolors[rn2_on_display_rng(SIZE(hcolors))]
: colorpref;
} }
/* return a random real color unless hallucinating */ /* return a random real color unless hallucinating */
+3 -3
View File
@@ -1076,7 +1076,7 @@ struct obj *obj;
if ((u.dx || u.dy) && (bhitpos.x != u.ux || bhitpos.y != u.uy)) { if ((u.dx || u.dy) && (bhitpos.x != u.ux || bhitpos.y != u.uy)) {
int x = bhitpos.x - u.dx, y = bhitpos.y - u.dy; int x = bhitpos.x - u.dx, y = 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)) { while (isok(x,y) && (x != u.ux || y != u.uy)) {
tmp_at(x, y); tmp_at(x, y);
delay_output(); delay_output();
@@ -1145,7 +1145,7 @@ boolean twoweap; /* used to restore twoweapon mode if wielded weapon returns */
bhitpos.x = mon->mx; bhitpos.x = mon->mx;
bhitpos.y = mon->my; bhitpos.y = mon->my;
if (tethered_weapon) 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) { } else if (u.dz) {
if (u.dz < 0 if (u.dz < 0
/* Mjollnir must we wielded to be thrown--caller verifies this; /* Mjollnir must we wielded to be thrown--caller verifies this;
@@ -1374,7 +1374,7 @@ boolean twoweap; /* used to restore twoweapon mode if wielded weapon returns */
} }
if (!IS_SOFT(levl[bhitpos.x][bhitpos.y].typ) && breaktest(obj)) { if (!IS_SOFT(levl[bhitpos.x][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(bhitpos.x, bhitpos.y); tmp_at(bhitpos.x, bhitpos.y);
delay_output(); delay_output();
tmp_at(DISP_END, 0); tmp_at(DISP_END, 0);
+2 -2
View File
@@ -18,7 +18,7 @@ char *outbuf;
/* a random engraving may come from the "rumors" file, /* a random engraving may come from the "rumors" file,
or from the "engrave" file (formerly in an array here) */ or from the "engrave" file (formerly in an array here) */
if (!rn2(4) || !(rumor = getrumor(0, outbuf, TRUE)) || !*rumor) 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); wipeout_text(outbuf, (int) (strlen(outbuf) / 4), 0);
return outbuf; return outbuf;
@@ -1294,7 +1294,7 @@ const char *str;
/* Engrave the headstone */ /* Engrave the headstone */
del_engr_at(x, y); del_engr_at(x, y);
if (!str) if (!str)
str = get_rnd_text(EPITAPHFILE, buf); str = get_rnd_text(EPITAPHFILE, buf, rn2);
make_engr_at(x, y, str, 0L, HEADSTONE); make_engr_at(x, y, str, 0L, HEADSTONE);
return; return;
} }
+2 -2
View File
@@ -1466,7 +1466,7 @@ domove_core()
if (context.run >= 2) { if (context.run >= 2) {
if (iflags.mention_walls) { if (iflags.mention_walls) {
if (trap && trap->tseen) { 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.", You("stop in front of %s.",
an(defsyms[trap_to_defsym(tt)].explanation)); an(defsyms[trap_to_defsym(tt)].explanation));
@@ -2709,7 +2709,7 @@ lookaround()
goto bcorr; /* if you must */ goto bcorr; /* if you must */
if (x == u.ux + u.dx && y == u.uy + u.dy) { if (x == u.ux + u.dx && y == u.uy + u.dy) {
if (iflags.mention_walls) { 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.", You("stop in front of %s.",
an(defsyms[trap_to_defsym(tt)].explanation)); an(defsyms[trap_to_defsym(tt)].explanation));
} }
+55 -28
View File
@@ -51,6 +51,8 @@
boolean fuzzymatch (const char *, const char *, boolean fuzzymatch (const char *, const char *,
const char *, boolean) const char *, boolean)
void setrandom (void) void setrandom (void)
void init_random (fn)
void reseed_random (fn)
time_t getnow (void) time_t getnow (void)
int getyear (void) int getyear (void)
char * yymmdd (time_t) char * yymmdd (time_t)
@@ -848,44 +850,69 @@ extern struct tm *FDECL(localtime, (time_t *));
#endif #endif
STATIC_DCL struct tm *NDECL(getlt); STATIC_DCL struct tm *NDECL(getlt);
void /* Sets the seed for the random number generator */
setrandom() #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 /* the types are different enough here that sweeping the different
* routine names into one via #defines is even more confusing * 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); srandom((unsigned int) seed);
#else # else
#if defined(__APPLE__) || defined(BSD) || defined(LINUX) || defined(ULTRIX) \ # if defined(__APPLE__) || defined(BSD) || defined(LINUX) || defined(ULTRIX) \
|| defined(CYGWIN32) /* system srandom() */ || defined(CYGWIN32) /* system srandom() */
#if defined(BSD) && !defined(POSIX_TYPES) && defined(SUNOS4) # if defined(BSD) && !defined(POSIX_TYPES) && defined(SUNOS4)
(void) (void)
#endif # endif
srandom((int) seed); srandom((int) seed);
#else # else
#ifdef UNIX /* system srand48() */ # ifdef UNIX /* system srand48() */
srand48((long) seed); srand48((long) seed);
#else /* poor quality system routine */ # else /* poor quality system routine */
srand((int) seed); 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 time_t
+4 -3
View File
@@ -2691,8 +2691,8 @@ long *out_cnt;
any.a_obj = otmp; any.a_obj = otmp;
else else
any.a_char = ilet; 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,
doname(otmp), MENU_UNSELECTED); 0, ATR_NONE, doname(otmp), MENU_UNSELECTED);
} }
} }
if (flags.sortpack) { if (flags.sortpack) {
@@ -2805,7 +2805,8 @@ char avoidlet;
classcount++; classcount++;
} }
any.a_char = ilet; 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); doname(otmp), MENU_UNSELECTED);
} }
} }
+161
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;
}
+6
View File
@@ -982,6 +982,9 @@ mklev()
struct mkroom *croom; struct mkroom *croom;
int ridx; int ridx;
reseed_random(rn2);
reseed_random(rn2_on_display_rng);
init_mapseen(&u.uz); init_mapseen(&u.uz);
if (getbones()) if (getbones())
return; return;
@@ -1009,6 +1012,9 @@ mklev()
entered; rooms[].orig_rtype always retains original rtype value */ entered; rooms[].orig_rtype always retains original rtype value */
for (ridx = 0; ridx < SIZE(rooms); ridx++) for (ridx = 0; ridx < SIZE(rooms); ridx++)
rooms[ridx].orig_rtype = rooms[ridx].rtype; rooms[ridx].orig_rtype = rooms[ridx].rtype;
reseed_random(rn2);
reseed_random(rn2_on_display_rng);
} }
void void
+1 -1
View File
@@ -532,7 +532,7 @@ struct obj *obj; /* missile (or stack providing it) */
* be careful not to use either one after it's been freed. * be careful not to use either one after it's been freed.
*/ */
if (sym) 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 */ while (range-- > 0) { /* Actually the loop is always exited by break */
bhitpos.x += dx; bhitpos.x += dx;
bhitpos.y += dy; bhitpos.y += dy;
+1 -1
View File
@@ -1976,7 +1976,7 @@ struct monst *mtmp;
#ifdef CLIPPING #ifdef CLIPPING
cliparound(mtmp->mx, mtmp->my); cliparound(mtmp->mx, mtmp->my);
#endif #endif
show_glyph(mtmp->mx, mtmp->my, mon_to_glyph(mtmp)); show_glyph(mtmp->mx, mtmp->my, mon_to_glyph(mtmp, rn2));
display_self(); display_self();
You_feel("aggravated at %s.", noit_mon_nam(mtmp)); You_feel("aggravated at %s.", noit_mon_nam(mtmp));
display_nhwindow(WIN_MAP, TRUE); display_nhwindow(WIN_MAP, TRUE);
+3 -2
View File
@@ -691,8 +691,9 @@ initoptions_init()
/* set up the command parsing */ /* set up the command parsing */
reset_commands(TRUE); /* init */ reset_commands(TRUE); /* init */
/* initialize the random number generator */ /* initialize the random number generator(s) */
setrandom(); init_random(rn2);
init_random(rn2_on_display_rng);
/* for detection of configfile options specified multiple times */ /* for detection of configfile options specified multiple times */
iflags.opt_booldup = iflags.opt_compdup = (int *) 0; iflags.opt_booldup = iflags.opt_compdup = (int *) 0;
+4 -3
View File
@@ -381,7 +381,8 @@ char *buf, *monbuf;
buf[0] = monbuf[0] = '\0'; buf[0] = monbuf[0] = '\0';
glyph = glyph_at(x, y); glyph = glyph_at(x, y);
if (u.ux == x && u.uy == y && canspotself() 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)) { && (!iflags.terrainmode || (iflags.terrainmode & TER_MON) != 0)) {
/* fill in buf[] */ /* fill in buf[] */
(void) self_lookat(buf); (void) self_lookat(buf);
@@ -435,7 +436,7 @@ char *buf, *monbuf;
} else if (glyph_is_object(glyph)) { } else if (glyph_is_object(glyph)) {
look_at_object(buf, x, y, glyph); /* fill in buf[] */ look_at_object(buf, x, y, glyph); /* fill in buf[] */
} else if (glyph_is_trap(glyph)) { } 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 /* Trap detection displays a bear trap at locations having
* a trapped door or trapped container or both. * a trapped door or trapped container or both.
@@ -1487,7 +1488,7 @@ doidtrap()
if (u.dz < 0 ? is_hole(tt) : tt == ROCKTRAP) if (u.dz < 0 ? is_hole(tt) : tt == ROCKTRAP)
break; break;
} }
tt = what_trap(tt); tt = what_trap(tt, rn2_on_display_rng);
pline("That is %s%s%s.", pline("That is %s%s%s.",
an(defsyms[trap_to_defsym(tt)].explanation), an(defsyms[trap_to_defsym(tt)].explanation),
!trap->madeby_u !trap->madeby_u
+2 -2
View File
@@ -914,7 +914,7 @@ boolean FDECL((*allow), (OBJ_P)); /* allow function */
} }
any.a_obj = curr; 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 (qflags & USE_INVLET) ? curr->invlet
: (first && curr->oclass == COIN_CLASS) ? '$' : 0, : (first && curr->oclass == COIN_CLASS) ? '$' : 0,
def_oc_syms[(int) objects[curr->otyp].oc_class].sym, def_oc_syms[(int) objects[curr->otyp].oc_class].sym,
@@ -939,7 +939,7 @@ boolean FDECL((*allow), (OBJ_P)); /* allow function */
fake_hero_object = zeroobj; fake_hero_object = zeroobj;
fake_hero_object.quan = 1L; /* not strictly necessary... */ fake_hero_object.quan = 1L; /* not strictly necessary... */
any.a_obj = &fake_hero_object; any.a_obj = &fake_hero_object;
add_menu(win, mon_to_glyph(&youmonst), &any, add_menu(win, mon_to_glyph(&youmonst, rn2_on_display_rng), &any,
/* fake inventory letter, no group accelerator */ /* fake inventory letter, no group accelerator */
CONTAINED_SYM, 0, ATR_NONE, an(self_lookat(buf)), CONTAINED_SYM, 0, ATR_NONE, an(self_lookat(buf)),
MENU_UNSELECTED); MENU_UNSELECTED);
+9 -4
View File
@@ -2095,13 +2095,18 @@ aligntyp alignment;
if (!Hallucination) if (!Hallucination)
return align_gname(alignment); 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 /* 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 do
which = randrole(); which = rn2_on_display_rng(rolecount);
while (!roles[which].lgod); while (!roles[which].lgod);
switch (rn2(9)) { switch (rn2_on_display_rng(9)) {
case 0: case 0:
case 1: case 1:
gnam = roles[which].lgod; gnam = roles[which].lgod;
@@ -2116,7 +2121,7 @@ aligntyp alignment;
break; break;
case 6: case 6:
case 7: case 7:
gnam = hallu_gods[rn2(sizeof hallu_gods / sizeof *hallu_gods)]; gnam = hallu_gods[rn2_on_display_rng(SIZE(hallu_gods))];
break; break;
case 8: case 8:
gnam = Moloch; gnam = Moloch;
+77
View File
@@ -4,6 +4,74 @@
#include "hack.h" #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 */ /* "Rand()"s definition is determined by [OS]conf.h */
#if defined(LINT) && defined(UNIX) /* rand() is long... */ #if defined(LINT) && defined(UNIX) /* rand() is long... */
extern int NDECL(rand); extern int NDECL(rand);
@@ -16,6 +84,15 @@ extern int NDECL(rand);
#define RND(x) ((int) ((Rand() >> 3) % (x))) #define RND(x) ((int) ((Rand() >> 3) % (x)))
#endif #endif
#endif /* LINT */ #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 */ /* 0 <= rn2(x) < x */
int int
+7 -5
View File
@@ -125,12 +125,12 @@ boolean exclude_cookie;
case 2: /*(might let a bogus input arg sneak thru)*/ case 2: /*(might let a bogus input arg sneak thru)*/
case 1: case 1:
beginning = (long) true_rumor_start; beginning = (long) true_rumor_start;
tidbit = Rand() % true_rumor_size; tidbit = rn2(true_rumor_size);
break; break;
case 0: /* once here, 0 => false rather than "either"*/ case 0: /* once here, 0 => false rather than "either"*/
case -1: case -1:
beginning = (long) false_rumor_start; beginning = (long) false_rumor_start;
tidbit = Rand() % false_rumor_size; tidbit = rn2(false_rumor_size);
break; break;
default: default:
impossible("strange truth value for rumor"); impossible("strange truth value for rumor");
@@ -280,11 +280,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 * char *
get_rnd_text(fname, buf) get_rnd_text(fname, buf, rng)
const char *fname; const char *fname;
char *buf; char *buf;
int FDECL((*rng), (int));
{ {
dlb *fh; dlb *fh;
@@ -305,7 +307,7 @@ char *buf;
(void) dlb_fseek(fh, 0L, SEEK_END); (void) dlb_fseek(fh, 0L, SEEK_END);
endtxt = dlb_ftell(fh); endtxt = dlb_ftell(fh);
sizetxt = endtxt - starttxt; sizetxt = endtxt - starttxt;
tidbit = Rand() % sizetxt; tidbit = rng(sizetxt);
(void) dlb_fseek(fh, starttxt + tidbit, SEEK_SET); (void) dlb_fseek(fh, starttxt + tidbit, SEEK_SET);
(void) dlb_fgets(line, sizeof line, fh); (void) dlb_fgets(line, sizeof line, fh);
+1 -1
View File
@@ -1814,7 +1814,7 @@ int style;
delaycnt = 1; delaycnt = 1;
if (!cansee(bhitpos.x, bhitpos.y)) if (!cansee(bhitpos.x, bhitpos.y))
curs_on_u(); 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(bhitpos.x, bhitpos.y); tmp_at(bhitpos.x, bhitpos.y);
} }
/* Mark a spot to place object in bones files to prevent /* Mark a spot to place object in bones files to prevent
+1 -1
View File
@@ -2023,7 +2023,7 @@ struct monst *mdef;
{ {
if (!Invisible) { if (!Invisible) {
map_location(u.ux, u.uy, TRUE); map_location(u.ux, u.uy, TRUE);
tmp_at(DISP_ALWAYS, mon_to_glyph(&youmonst)); tmp_at(DISP_ALWAYS, mon_to_glyph(&youmonst, rn2_on_display_rng));
tmp_at(mdef->mx, mdef->my); tmp_at(mdef->mx, mdef->my);
} }
You("engulf %s!", mon_nam(mdef)); You("engulf %s!", mon_nam(mdef));
+4 -3
View File
@@ -457,13 +457,14 @@ boolean use_detection_glyph;
struct wseg *curr = wtails[worm->wormno]; struct wseg *curr = wtails[worm->wormno];
/* if (!mtmp->wormno) return; bullet proofing */ /* if (!mtmp->wormno) return; bullet proofing */
int what_tail = what_mon(PM_LONG_WORM_TAIL, newsym_rn2);
while (curr != wheads[worm->wormno]) { while (curr != wheads[worm->wormno]) {
num = use_detection_glyph num = use_detection_glyph
? detected_monnum_to_glyph(what_mon(PM_LONG_WORM_TAIL)) ? detected_monnum_to_glyph(what_tail)
: (worm->mtame : (worm->mtame
? petnum_to_glyph(what_mon(PM_LONG_WORM_TAIL)) ? petnum_to_glyph(what_tail)
: monnum_to_glyph(what_mon(PM_LONG_WORM_TAIL))); : monnum_to_glyph(what_tail));
show_glyph(curr->wx, curr->wy, num); show_glyph(curr->wx, curr->wy, num);
curr = curr->nseg; curr = curr->nseg;
} }
+3 -3
View File
@@ -1488,7 +1488,7 @@ int id;
/* now change it into something laid by the hero */ /* now change it into something laid by the hero */
while (tryct--) { while (tryct--) {
mnum = can_be_hatched(random_monster()); mnum = can_be_hatched(random_monster(rn2));
if (mnum != NON_PM && !dead_species(mnum, TRUE)) { if (mnum != NON_PM && !dead_species(mnum, TRUE)) {
otmp->spe = 1; /* laid by hero */ otmp->spe = 1; /* laid by hero */
set_corpsenm(otmp, mnum); /* also sets hatch timer */ set_corpsenm(otmp, mnum); /* also sets hatch timer */
@@ -3200,9 +3200,9 @@ struct obj **pobj; /* object tossed/used, set to NULL
} else if (weapon == THROWN_TETHERED_WEAPON && obj) { } else if (weapon == THROWN_TETHERED_WEAPON && obj) {
tethered_weapon = TRUE; tethered_weapon = TRUE;
weapon = THROWN_WEAPON; /* simplify if's that follow below */ 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) } 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) { while (range-- > 0) {
int x, y; int x, y;
+11
View File
@@ -519,4 +519,15 @@ unsigned setvalue;
return (regs.x.dx); return (regs.x.dx);
} }
unsigned long
sys_random_seed(VOID_ARGS)
{
unsigned long ourseed = 0UL;
time_t datetime = 0;
(void) time(&datetime);
ourseed = (unsigned long) datetime;
return ourseed;
}
#endif /* MSDOS */ #endif /* MSDOS */
+6 -5
View File
@@ -441,9 +441,9 @@ HACKCSRC = allmain.c alloc.c apply.c artifact.c attrib.c ball.c bones.c \
botl.c cmd.c dbridge.c decl.c detect.c dig.c display.c dlb.c do.c \ botl.c cmd.c dbridge.c decl.c detect.c dig.c display.c dlb.c do.c \
do_name.c do_wear.c dog.c dogmove.c dokick.c dothrow.c drawing.c \ do_name.c do_wear.c dog.c dogmove.c dokick.c dothrow.c drawing.c \
dungeon.c eat.c end.c engrave.c exper.c explode.c extralev.c \ dungeon.c eat.c end.c engrave.c exper.c explode.c extralev.c \
files.c fountain.c hack.c hacklib.c invent.c light.c lock.c \ files.c fountain.c hack.c hacklib.c invent.c isaac64.c light.c \
mail.c makemon.c mapglyph.c mcastu.c mhitm.c mhitu.c minion.c \ lock.c mail.c makemon.c mapglyph.c mcastu.c mhitm.c mhitu.c \
mklev.c mkmap.c \ minion.c mklev.c mkmap.c \
mkmaze.c mkobj.c mkroom.c mon.c mondata.c monmove.c monst.c \ mkmaze.c mkobj.c mkroom.c mon.c mondata.c monmove.c monst.c \
mplayer.c mthrowu.c muse.c music.c o_init.c objects.c objnam.c \ mplayer.c mthrowu.c muse.c music.c o_init.c objects.c objnam.c \
options.c pager.c pickup.c pline.c polyself.c potion.c pray.c \ options.c pager.c pickup.c pline.c polyself.c potion.c pray.c \
@@ -508,8 +508,8 @@ HOBJ = $(FIRSTOBJ) allmain.o alloc.o apply.o artifact.o attrib.o ball.o \
bones.o botl.o cmd.o dbridge.o decl.o detect.o dig.o display.o dlb.o \ bones.o botl.o cmd.o dbridge.o decl.o detect.o dig.o display.o dlb.o \
do.o do_name.o do_wear.o dog.o dogmove.o dokick.o dothrow.o \ do.o do_name.o do_wear.o dog.o dogmove.o dokick.o dothrow.o \
drawing.o dungeon.o eat.o end.o engrave.o exper.o explode.o \ drawing.o dungeon.o eat.o end.o engrave.o exper.o explode.o \
extralev.o files.o fountain.o hack.o hacklib.o invent.o light.o \ extralev.o files.o fountain.o hack.o hacklib.o invent.o isaac64.o \
lock.o mail.o makemon.o mapglyph.o mcastu.o mhitm.o mhitu.o \ light.o lock.o mail.o makemon.o mapglyph.o mcastu.o mhitm.o mhitu.o \
minion.o mklev.o mkmap.o \ minion.o mklev.o mkmap.o \
mkmaze.o mkobj.o mkroom.o mon.o mondata.o monmove.o \ mkmaze.o mkobj.o mkroom.o mon.o mondata.o monmove.o \
mplayer.o mthrowu.o muse.o music.o o_init.o objnam.o options.o \ mplayer.o mthrowu.o muse.o music.o o_init.o objnam.o options.o \
@@ -1013,6 +1013,7 @@ fountain.o: fountain.c $(HACK_H)
hack.o: hack.c $(HACK_H) hack.o: hack.c $(HACK_H)
hacklib.o: hacklib.c $(HACK_H) hacklib.o: hacklib.c $(HACK_H)
invent.o: invent.c $(HACK_H) invent.o: invent.c $(HACK_H)
isaac64.o: isaac64.c ../include/isaac64.h ../include/integer.h
light.o: light.c $(HACK_H) ../include/lev.h light.o: light.c $(HACK_H) ../include/lev.h
lock.o: lock.c $(HACK_H) lock.o: lock.c $(HACK_H)
mail.o: mail.c $(HACK_H) ../include/mail.h mail.o: mail.c $(HACK_H) ../include/mail.h
+1 -1
View File
@@ -69,7 +69,7 @@ CC=gcc
# #
#CFLAGS+=-W -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -DGCC_WARN #CFLAGS+=-W -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -DGCC_WARN
CFLAGS+=-Wall -Wextra -Wno-missing-field-initializers -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings -DGCC_WARN -ansi -pedantic CFLAGS+=-Wall -Wextra -Wno-missing-field-initializers -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings -DGCC_WARN -ansi -pedantic -Wno-long-long
# As of LLVM build 2336.1.00, this gives dozens of spurious messages, so # As of LLVM build 2336.1.00, this gives dozens of spurious messages, so
# leave it out by default. # leave it out by default.
#CFLAGS+=-Wunreachable-code #CFLAGS+=-Wunreachable-code
+1 -1
View File
@@ -69,7 +69,7 @@ CC=gcc
# #
#CFLAGS+=-W -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -DGCC_WARN #CFLAGS+=-W -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -DGCC_WARN
CFLAGS+=-Wall -Wextra -Wno-missing-field-initializers -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings -DGCC_WARN -ansi -pedantic CFLAGS+=-Wall -Wextra -Wno-missing-field-initializers -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings -DGCC_WARN -ansi -pedantic -Wno-long-long
# As of LLVM build 2336.1.00, this gives dozens of spurious messages, so # As of LLVM build 2336.1.00, this gives dozens of spurious messages, so
# leave it out by default. # leave it out by default.
#CFLAGS+=-Wunreachable-code #CFLAGS+=-Wunreachable-code
+1 -1
View File
@@ -53,7 +53,7 @@ GAMEGRP = games
#WANT_SOURCE_INSTALL=1 #WANT_SOURCE_INSTALL=1
#CC=gcc -W -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -DGCC_WARN #CC=gcc -W -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -DGCC_WARN
CC=gcc -Wall -Wextra -Wno-missing-field-initializers -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings -DGCC_WARN -ansi -pedantic CC=gcc -Wall -Wextra -Wno-missing-field-initializers -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings -DGCC_WARN -ansi -pedantic -Wno-long-long
# #
# You shouldn't need to change anything below here. # You shouldn't need to change anything below here.
+1 -1
View File
@@ -63,7 +63,7 @@ CC=gcc
# #
#CFLAGS+=-W -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -DGCC_WARN #CFLAGS+=-W -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -DGCC_WARN
CFLAGS+=-Wall -Wextra -Wno-missing-field-initializers -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings -DGCC_WARN -ansi -pedantic CFLAGS+=-Wall -Wextra -Wno-missing-field-initializers -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings -DGCC_WARN -ansi -pedantic -Wno-long-long
# As of LLVM build 2336.1.00, this gives dozens of spurious messages, so # As of LLVM build 2336.1.00, this gives dozens of spurious messages, so
# leave it out by default. # leave it out by default.
#CFLAGS+=-Wunreachable-code #CFLAGS+=-Wunreachable-code
+1 -1
View File
@@ -70,7 +70,7 @@ CC=gcc
# #
#CFLAGS+=-W -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -DGCC_WARN #CFLAGS+=-W -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -DGCC_WARN
CFLAGS+=-Wall -Wextra -Wno-missing-field-initializers -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings -DGCC_WARN -ansi -pedantic CFLAGS+=-Wall -Wextra -Wno-missing-field-initializers -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wwrite-strings -DGCC_WARN -ansi -pedantic -Wno-long-long
# As of LLVM build 2336.1.00, this gives dozens of spurious messages, so # As of LLVM build 2336.1.00, this gives dozens of spurious messages, so
# leave it out by default. # leave it out by default.
#CFLAGS+=-Wunreachable-code #CFLAGS+=-Wunreachable-code
+32
View File
@@ -765,4 +765,36 @@ error:
} }
#endif #endif
unsigned long
sys_random_seed()
{
unsigned long seed;
unsigned long pid = (unsigned long) getpid();
boolean no_seed = TRUE;
#ifdef DEV_RANDOM
FILE *fptr = NULL;
fptr = fopen(DEV_RANDOM, "r");
if (fptr) {
fread(&seed, sizeof(long), 1, fptr);
has_strong_rngseed = TRUE; /* decl.c */
no_seed = FALSE;
fclose(fptr);
} else {
/* leaves clue, doesn't exit */
paniclog("sys_random_seed", "falling back to weak seed");
}
#endif
if (no_seed) {
seed = (unsigned long) getnow(); /* time((TIME_type) 0) */
/* Quick dirty band-aid to prevent PRNG prediction */
if (pid) {
if (!(pid & 3L))
pid -= 1L;
seed *= pid;
}
}
return seed;
}
/*unixmain.c*/ /*unixmain.c*/
+16
View File
@@ -465,4 +465,20 @@ wd_message()
You("are in non-scoring explore/discovery mode."); You("are in non-scoring explore/discovery mode.");
} }
unsigned long
sys_random_seed()
{
unsigned long seed;
unsigned long pid = (unsigned long) getpid();
seed = (unsigned long) getnow(); /* time((TIME_type) 0) */
/* Quick dirty band-aid to prevent PRNG prediction */
if (pid) {
if (!(pid & 3L))
pid -= 1L;
seed *= pid;
}
return seed;
}
/*vmsmain.c*/ /*vmsmain.c*/
+12 -5
View File
@@ -129,9 +129,13 @@ OBJ = o
# (see pcconf.h). Set to nothing if not used. # (see pcconf.h). Set to nothing if not used.
# #
RANDOM = $(OBJ)\random.o RANDOM = $(OBJ)\isaac64.o
#RANDOM = $(OBJ)\random.o
#RANDOM = #RANDOM =
BCRYPT=
! IF ("$(RANDOM)"=="$(OBJ)\isaac64.o")
BCRYPT=bcrypt.lib
! ENDIF
WINPFLAG= -DTILES -DMSWIN_GRAPHICS -DWIN32CON WINPFLAG= -DTILES -DMSWIN_GRAPHICS -DWIN32CON
# To store all the level files, # To store all the level files,
@@ -460,7 +464,8 @@ CURSESLIB=
ccommon= -c -nologo -D"_CONSOLE" -D"_CRT_NONSTDC_NO_DEPRECATE" -D"_CRT_SECURE_NO_DEPRECATE" \ ccommon= -c -nologo -D"_CONSOLE" -D"_CRT_NONSTDC_NO_DEPRECATE" -D"_CRT_SECURE_NO_DEPRECATE" \
-D"_LIB" -D"_SCL_SECURE_NO_DEPRECATE" -D"_VC80_UPGRADE=0x0600" -D"DLB" -D"_MBCS" \ -D"_LIB" -D"_SCL_SECURE_NO_DEPRECATE" -D"_VC80_UPGRADE=0x0600" -D"DLB" -D"_MBCS" \
-DCRTAPI1=_cdecl -DCRTAPI2=_cdecl -D"NDEBUG" -D"YY_NO_UNISTD_H" $(CURSESDEF) \ -DCRTAPI1=_cdecl -DCRTAPI2=_cdecl -D"NDEBUG" -D"YY_NO_UNISTD_H" \
-DHAS_STDINT_H -DHAS_INLINE $(CURSESDEF) \
-EHsc -fp:precise -Gd -GF -GS -Gy \ -EHsc -fp:precise -Gd -GF -GS -Gy \
$(CL_RECENT) -WX- -Zc:forScope -Zc:wchar_t -Zi $(CL_RECENT) -WX- -Zc:forScope -Zc:wchar_t -Zi
cdebug= -analyze- -D"_DEBUG" -Gm -MTd -RTC1 -Od cdebug= -analyze- -D"_DEBUG" -Gm -MTd -RTC1 -Od
@@ -801,7 +806,7 @@ $(GAMEDIR)\NetHack.exe : $(O)gamedir.tag $(PDCLIB) $(O)tile.o $(O)nttty.o $(O)gu
@if not exist $(GAMEDIR)\*.* mkdir $(GAMEDIR) @if not exist $(GAMEDIR)\*.* mkdir $(GAMEDIR)
@echo Linking $(@:\=/) @echo Linking $(@:\=/)
$(link) $(lflagsBuild) $(conlflags) /STACK:2048 /PDB:$(GAMEDIR)\$(@B).PDB /MAP:$(O)$(@B).MAP \ $(link) $(lflagsBuild) $(conlflags) /STACK:2048 /PDB:$(GAMEDIR)\$(@B).PDB /MAP:$(O)$(@B).MAP \
$(LIBS) $(PDCLIB) $(conlibs) -out:$@ @<<$(@B).lnk $(LIBS) $(PDCLIB) $(conlibs) $(BCRYPT) -out:$@ @<<$(@B).lnk
$(GAMEOBJ) $(GAMEOBJ)
$(TTYOBJ) $(TTYOBJ)
$(O)nttty.o $(O)nttty.o
@@ -824,7 +829,7 @@ $(GAMEDIR)\NetHackW.exe : $(O)gamedir.tag $(O)tile.o $(O)ttystub.o \
@if not exist $(GAMEDIR)\*.* mkdir $(GAMEDIR) @if not exist $(GAMEDIR)\*.* mkdir $(GAMEDIR)
@echo Linking $(@:\=/) @echo Linking $(@:\=/)
$(link) $(lflagsBuild) $(guilflags) /STACK:2048 /PDB:$(GAMEDIR)\$(@B).PDB \ $(link) $(lflagsBuild) $(guilflags) /STACK:2048 /PDB:$(GAMEDIR)\$(@B).PDB \
/MAP:$(O)$(@B).MAP $(LIBS) $(PDCLIB) $(guilibs) $(COMCTRL) -out:$@ @<<$(@B).lnk /MAP:$(O)$(@B).MAP $(LIBS) $(PDCLIB) $(guilibs) $(COMCTRL) $(BCRYPT) -out:$@ @<<$(@B).lnk
$(GAMEOBJ) $(GAMEOBJ)
$(GUIOBJ) $(GUIOBJ)
$(O)tile.o $(O)tile.o
@@ -1514,6 +1519,8 @@ $(O)tos.o: ..\sys\atari\tos.c $(HACK_H) $(INCL)\tcap.h
@$(CC) $(cflagsBuild) -Fo$@ ..\sys\atari\tos.c @$(CC) $(cflagsBuild) -Fo$@ ..\sys\atari\tos.c
$(O)pctty.o: ..\sys\share\pctty.c $(HACK_H) $(O)pctty.o: ..\sys\share\pctty.c $(HACK_H)
@$(CC) $(cflagsBuild) -Fo$@ ..\sys\share\pctty.c @$(CC) $(cflagsBuild) -Fo$@ ..\sys\share\pctty.c
$(O)isaac64.o: ..\src\isaac64.c $(HACK_H) $(INCL)\isaac64.h $(INCL)\integer.h
@$(CC) $(cflagsBuild) -Fo$@ ..\src\isaac64.c
$(O)random.o: ..\sys\share\random.c $(HACK_H) $(O)random.o: ..\sys\share\random.c $(HACK_H)
@$(CC) $(cflagsBuild) -Fo$@ ..\sys\share\random.c @$(CC) $(cflagsBuild) -Fo$@ ..\sys\share\random.c
$(O)ioctl.o: ..\sys\share\ioctl.c $(HACK_H) $(INCL)\tcap.h $(O)ioctl.o: ..\sys\share\ioctl.c $(HACK_H) $(INCL)\tcap.h
+48
View File
@@ -680,6 +680,54 @@ char *name;
} }
return; return;
} }
#include <bcrypt.h> /* Windows Crypto Next Gen (CNG) */
#ifndef STATUS_SUCCESS
#define STATUS_SUCCESS 0
#endif
#ifndef STATUS_NOT_FOUND
#define STATUS_NOT_FOUND 0xC0000225
#endif
#ifndef STATUS_UNSUCCESSFUL
#define STATUS_UNSUCCESSFUL 0xC0000001
#endif
unsigned long
sys_random_seed(VOID_ARGS)
{
unsigned long ourseed = 0UL;
BCRYPT_ALG_HANDLE hRa = (BCRYPT_ALG_HANDLE) 0;
NTSTATUS status = STATUS_UNSUCCESSFUL;
boolean Plan_B = TRUE;
status = BCryptOpenAlgorithmProvider(&hRa, BCRYPT_RNG_ALGORITHM,
(LPCWSTR) 0, 0);
if (hRa && status == STATUS_SUCCESS) {
status = BCryptGenRandom(hRa, (PUCHAR) &ourseed,
(ULONG) sizeof ourseed, 0);
if (status == STATUS_SUCCESS) {
BCryptCloseAlgorithmProvider(hRa,0);
has_strong_rngseed = TRUE;
Plan_B = FALSE;
}
}
if (Plan_B) {
time_t datetime = 0;
const char *emsg;
if (status == STATUS_NOT_FOUND)
emsg = "BCRYPT_RNG_ALGORITHM not avail, falling back";
else
emsg = "Other failure than algorithm not avail";
paniclog("sys_random_seed", emsg); /* leaves clue, doesn't exit */
(void) time(&datetime);
ourseed = (unsigned long) datetime;
}
return ourseed;
}
#endif /* WIN32 */ #endif /* WIN32 */
/*winnt.c*/ /*winnt.c*/
+3 -2
View File
@@ -37,7 +37,7 @@
<PreprocessorDefinitions>TILES;WIN32CON;DLB;MSWIN_GRAPHICS;SAFEPROCS;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>TILES;WIN32CON;DLB;MSWIN_GRAPHICS;SAFEPROCS;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile> </ClCompile>
<Link> <Link>
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;winmm.lib;Winmm.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;winmm.lib;Winmm.lib;bcrypt.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
@@ -76,6 +76,7 @@
<ClCompile Include="$(SrcDir)hack.c" /> <ClCompile Include="$(SrcDir)hack.c" />
<ClCompile Include="$(SrcDir)hacklib.c" /> <ClCompile Include="$(SrcDir)hacklib.c" />
<ClCompile Include="$(SrcDir)invent.c" /> <ClCompile Include="$(SrcDir)invent.c" />
<ClCompile Include="$(SrcDir)isaac64.c" />
<ClCompile Include="$(SrcDir)light.c" /> <ClCompile Include="$(SrcDir)light.c" />
<ClCompile Include="$(SrcDir)lock.c" /> <ClCompile Include="$(SrcDir)lock.c" />
<ClCompile Include="$(SrcDir)mail.c" /> <ClCompile Include="$(SrcDir)mail.c" />
@@ -151,7 +152,6 @@
<ClCompile Include="$(SrcDir)zap.c" /> <ClCompile Include="$(SrcDir)zap.c" />
<ClCompile Include="$(SysShareDir)cppregex.cpp" /> <ClCompile Include="$(SysShareDir)cppregex.cpp" />
<ClCompile Include="$(SysShareDir)nhlan.c" /> <ClCompile Include="$(SysShareDir)nhlan.c" />
<ClCompile Include="$(SysShareDir)random.c" />
<ClCompile Include="$(SysWinntDir)ntsound.c" /> <ClCompile Include="$(SysWinntDir)ntsound.c" />
<ClCompile Include="$(SysWinntDir)nttty.c" /> <ClCompile Include="$(SysWinntDir)nttty.c" />
<ClCompile Include="$(SysWinntDir)stubs.c"> <ClCompile Include="$(SysWinntDir)stubs.c">
@@ -194,6 +194,7 @@
<ClInclude Include="$(IncDir)func_tab.h" /> <ClInclude Include="$(IncDir)func_tab.h" />
<ClInclude Include="$(IncDir)global.h" /> <ClInclude Include="$(IncDir)global.h" />
<ClInclude Include="$(IncDir)hack.h" /> <ClInclude Include="$(IncDir)hack.h" />
<ClInclude Include="$(IncDir)isaac64.h" />
<ClInclude Include="$(IncDir)lev.h" /> <ClInclude Include="$(IncDir)lev.h" />
<ClInclude Include="$(IncDir)mextra.h" /> <ClInclude Include="$(IncDir)mextra.h" />
<ClInclude Include="$(IncDir)mfndpos.h" /> <ClInclude Include="$(IncDir)mfndpos.h" />
+2 -2
View File
@@ -28,7 +28,7 @@
</ResourceCompile> </ResourceCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
<AdditionalDependencies>comctl32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>comctl32.lib;winmm.lib;bcrypt.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
<Manifest> <Manifest>
<AdditionalManifestFiles>$(WinWin32Dir)NethackW.exe.manifest;%(AdditionalManifestFiles)</AdditionalManifestFiles> <AdditionalManifestFiles>$(WinWin32Dir)NethackW.exe.manifest;%(AdditionalManifestFiles)</AdditionalManifestFiles>
@@ -70,6 +70,7 @@
<ClCompile Include="$(SrcDir)hack.c" /> <ClCompile Include="$(SrcDir)hack.c" />
<ClCompile Include="$(SrcDir)hacklib.c" /> <ClCompile Include="$(SrcDir)hacklib.c" />
<ClCompile Include="$(SrcDir)invent.c" /> <ClCompile Include="$(SrcDir)invent.c" />
<ClCompile Include="$(SrcDir)isaac64.c" />
<ClCompile Include="$(SrcDir)light.c" /> <ClCompile Include="$(SrcDir)light.c" />
<ClCompile Include="$(SrcDir)lock.c" /> <ClCompile Include="$(SrcDir)lock.c" />
<ClCompile Include="$(SrcDir)mail.c" /> <ClCompile Include="$(SrcDir)mail.c" />
@@ -146,7 +147,6 @@
<ClCompile Include="$(SrcDir)zap.c" /> <ClCompile Include="$(SrcDir)zap.c" />
<ClCompile Include="$(SysShareDir)cppregex.cpp" /> <ClCompile Include="$(SysShareDir)cppregex.cpp" />
<ClCompile Include="$(SysShareDir)nhlan.c" /> <ClCompile Include="$(SysShareDir)nhlan.c" />
<ClCompile Include="$(SysShareDir)random.c" />
<ClCompile Include="$(SysWinntDir)ntsound.c" /> <ClCompile Include="$(SysWinntDir)ntsound.c" />
<ClCompile Include="$(SysWinntDir)stubs.c"> <ClCompile Include="$(SysWinntDir)stubs.c">
<PreprocessorDefinitions>TTYSTUB;</PreprocessorDefinitions> <PreprocessorDefinitions>TTYSTUB;</PreprocessorDefinitions>