From: Eric S. Raymond Date: Wed, 24 May 2017 13:06:41 +0000 (-0400) Subject: Seed command fully implemented but apparently buggy. X-Git-Tag: seed~62 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=cf219e920bb038c9ac2c879adcfd048dc13bf3bc;p=open-adventure.git Seed command fully implemented but apparently buggy. Dwarf appearance is not yet reproducible. --- diff --git a/actions1.c b/actions1.c index b8fac67..0a1155d 100644 --- a/actions1.c +++ b/actions1.c @@ -625,6 +625,14 @@ L8340: if(!AT(RESER) && LOC != FIXED[RESER]-1) return(2011); RSPEAK(241); return(2); -L8350: printf("I see a SEED command. %s\n", raw_input); - return(2); +/* Seed. Expected in game logs to replicate the LCG state */ + +L8350: { + long sv; + int n; + n = sscanf(raw_input, "seed %ld\n", &sv); + if (n >= 1) + set_seed(sv); + return(2); + } } diff --git a/main.c b/main.c index d93c967..487eecf 100644 --- a/main.c +++ b/main.c @@ -58,6 +58,7 @@ static void do_command(FILE *); int main(int argc, char *argv[]) { int ch; + time_t starttime = time(NULL); /* Adventure (rev 2: 20 treasures) */ @@ -101,7 +102,7 @@ int main(int argc, char *argv[]) { lcgstate.a = 1093; lcgstate.c = 221587; lcgstate.m = 1048576; - set_seed_from_time(); + set_seed((long)starttime); /* Read the database if we have not yet done so */ @@ -134,6 +135,8 @@ L1: SETUP= -1; LIMIT=330; if(NOVICE)LIMIT=1000; + if (logfp) + fprintf(logfp, "seed %ld\n", starttime); for (;;) { do_command(stdin); } diff --git a/misc.c b/misc.c index 2e68901..f1bd954 100644 --- a/misc.c +++ b/misc.c @@ -723,7 +723,7 @@ L2: ATDWRF=I; -/* Utility routines (SETBIT, TSTBIT, set_seed_from_time, get_next_lcg_value, randrange, RNDVOC, BUG) */ +/* Utility routines (SETBIT, TSTBIT, set_seed, get_next_lcg_value, randrange, RNDVOC, BUG) */ #undef SETBIT long fSETBIT(long BIT) { @@ -758,11 +758,10 @@ long TSTBIT; #define TSTBIT(MASK,BIT) fTSTBIT(MASK,BIT) -void set_seed_from_time(void) +void set_seed(long seedval) { - /* Use the current system time to get seed the ISO rand() function, from which we get a seed for the LCG. */ - srand(time(NULL)); - lcgstate.x = (unsigned long) rand() % lcgstate.m; + srand(seedval); + lcgstate.x = (unsigned long) rand() % lcgstate.m; } unsigned long get_next_lcg_value(void) diff --git a/misc.h b/misc.h index 869c672..67f1e9b 100644 --- a/misc.h +++ b/misc.h @@ -72,6 +72,6 @@ extern long fIABS(long); #define IABS(N) fIABS(N) extern long fMOD(long,long); #define MOD(N,M) fMOD(N,M) -extern void set_seed_from_time(void); +extern void set_seed(long); extern unsigned long get_next_lcg_value(void); extern long randrange(long);