X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;ds=sidebyside;f=misc.c;h=e95439c01e67aaab20c523a31fb5dc31f5cbc96b;hb=18eac9f55d187366307d1d035988b29a9dc81a59;hp=111848e1d5231eb7a9d00b59f3b9dfe4485e9bc4;hpb=5ae76995d2e8d412f565481505e4c7bc37260bb1;p=open-adventure.git diff --git a/misc.c b/misc.c index 111848e..e95439c 100644 --- a/misc.c +++ b/misc.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "main.h" #include "share.h" /* for SETUP */ #include "misc.h" @@ -777,7 +778,7 @@ long randrange(long range) #undef RNDVOC long fRNDVOC(long CHAR, long FORCE) { -long DIV, I, J, RNDVOC; +long DIV, J, RNDVOC; /* Searches the vocabulary for a word whose second character is char, and * changes that word such that each of the other four characters is a @@ -786,22 +787,26 @@ long DIV, I, J, RNDVOC; RNDVOC=FORCE; - if(RNDVOC != 0) goto L3; - for (I=1; I<=5; I++) { - J=11+randrange(26); - if(I == 2)J=CHAR; - RNDVOC=RNDVOC*64+J; - } /* end loop */ -L3: J=10000; - DIV=64L*64L*64L; - for (I=1; I<=TABSIZ; I++) { - J=J+7; - if(MOD((ATAB[I]-J*J)/DIV,64L) == CHAR) goto L8; - /*etc*/ ; - } /* end loop */ - BUG(5); -L8: ATAB[I]=RNDVOC+J*J; + if (RNDVOC == 0) { + for (int I = 1; I <= 5; I++) { + J = 11 + randrange(26); + if (I == 2) + J = CHAR; + RNDVOC = RNDVOC * 64 + J; + } + } + + J = 10000; + DIV = 64L * 64L * 64L; + + for (int I = 1; I <= TABSIZ; I++) { + J = J + 7; + if (MOD((ATAB[I]-J*J)/DIV, 64L) == CHAR) + break; + } + + ATAB[I] = RNDVOC + J * J; return(RNDVOC); } @@ -1002,5 +1007,11 @@ L30: if(IN)IGNORE(fread(ARR,sizeof(long),250,F)); +void DATIME(long* D, long* T) { + struct timeval tv; + gettimeofday(&tv, NULL); + *D = (long) tv.tv_sec; + *T = (long) tv.tv_usec; +} long fIABS(N)long N; {return(N<0? -N : N);} long fMOD(N,M)long N, M; {return(N%M);}