-L3: J=10000;
- DIV=64L*64L*64L;
- /* 5 */ for (I=1; I<=TABSIZ; I++) {
- J=J+7;
- if(MOD((ATAB[I]-J*J)/DIV,64L) == CHAR) goto L8;
-L5: /*etc*/ ;
- } /* end loop */
- BUG(5);
-
-L8: ATAB[I]=RNDVOC+J*J;
- return(RNDVOC);
-}
-
-
-
-#define RNDVOC(CHAR,FORCE) fRNDVOC(CHAR,FORCE)
-#undef BUG
-void fBUG(NUM)long NUM; {
-
-/* THE FOLLOWING CONDITIONS ARE CURRENTLY CONSIDERED FATAL BUGS. NUMBERS < 20
- * ARE DETECTED WHILE READING THE DATABASE; THE OTHERS OCCUR AT "RUN TIME".
- * 0 MESSAGE LINE > 70 CHARACTERS
- * 1 NULL LINE IN MESSAGE
- * 2 TOO MANY WORDS OF MESSAGES
- * 3 TOO MANY TRAVEL OPTIONS
- * 4 TOO MANY VOCABULARY WORDS
- * 5 REQUIRED VOCABULARY WORD NOT FOUND
- * 6 TOO MANY RTEXT MESSAGES
- * 7 TOO MANY HINTS
- * 8 LOCATION HAS COND BIT BEING SET TWICE
- * 9 INVALID SECTION NUMBER IN DATABASE
- * 10 TOO MANY LOCATIONS
- * 11 TOO MANY CLASS OR TURN MESSAGES
- * 20 SPECIAL TRAVEL (500>L>300) EXCEEDS GOTO LIST
- * 21 RAN OFF END OF VOCABULARY TABLE
- * 22 VOCABULARY TYPE (N/1000) NOT BETWEEN 0 AND 3
- * 23 INTRANSITIVE ACTION VERB EXCEEDS GOTO LIST
- * 24 TRANSITIVE ACTION VERB EXCEEDS GOTO LIST
- * 25 CONDITIONAL TRAVEL ENTRY WITH NO ALTERNATIVE
- * 26 LOCATION HAS NO TRAVEL ENTRIES
- * 27 HINT NUMBER EXCEEDS GOTO LIST
- * 28 INVALID MONTH RETURNED BY DATE FUNCTION
- * 29 TOO MANY PARAMETERS GIVEN TO SETPRM */
+ return(AT);
+
+L2: AT=I;
+ return(AT);
+}
+
+/* Utility routines (SETBIT, TSTBIT, set_seed, get_next_lcg_value,
+ * randrange, RNDVOC, BUG) */
+
+long SETBIT(long bit) {
+/* Returns 2**bit for use in constructing bit-masks. */
+ 2 << bit;
+}
+
+bool TSTBIT(long mask, int bit) {
+/* Returns true if the specified bit is set in the mask. */
+ return((mask & (1 << bit)) != 0);
+}
+
+void set_seed(long seedval)
+{
+ lcgstate.x = (unsigned long) seedval % lcgstate.m;
+}
+
+unsigned long get_next_lcg_value(void)
+{
+ /* Return the LCG's current value, and then iterate it. */
+ unsigned long old_x = lcgstate.x;
+ lcgstate.x = (lcgstate.a * lcgstate.x + lcgstate.c) % lcgstate.m;
+ return(old_x);
+}
+
+long randrange(long range)
+{
+ /* Return a random integer from [0, range). */
+ long result = range * get_next_lcg_value() / lcgstate.m;
+ return(result);
+}
+
+long RNDVOC(long CHAR, long FORCE) {
+/* 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
+ * random letter. If force is non-zero, it is used as the new word.
+ * Returns the new word. */
+
+ long RND;
+
+ RND=FORCE;
+
+ if (RND == 0) {
+ for (int I = 1; I <= 5; I++) {
+ long J = 11 + randrange(26);
+ if (I == 2)
+ J = CHAR;
+ RND = RND * 64 + J;
+ }
+ }
+
+ long DIV = 64L * 64L * 64L;
+ for (int I = 1; I <= TABSIZ; I++) {
+ if (MOD(ATAB[I]/DIV, 64L) == CHAR)
+ {
+ ATAB[I] = RND;
+ break;
+ }
+ }
+
+ return(RND);
+}
+
+void BUG(long NUM) {
+
+/* The following conditions are currently considered fatal bugs. Numbers < 20
+ * are detected while reading the database; the others occur at "run time".
+ * 0 Message line > 70 characters
+ * 1 Null line in message
+ * 2 Too many words of messages
+ * 3 Too many travel options
+ * 4 Too many vocabulary words
+ * 5 Required vocabulary word not found
+ * 6 Too many RTEXT messages
+ * 7 Too many hints
+ * 8 Location has cond bit being set twice
+ * 9 Invalid section number in database
+ * 10 Too many locations
+ * 11 Too many class or turn messages
+ * 20 Special travel (500>L>300) exceeds goto list
+ * 21 Ran off end of vocabulary table
+ * 22 Vocabulary type (N/1000) not between 0 and 3
+ * 23 Intransitive action verb exceeds goto list
+ * 24 Transitive action verb exceeds goto list
+ * 25 Conditional travel entry with no alternative
+ * 26 Location has no travel entries
+ * 27 Hint number exceeds goto list
+ * 28 Invalid month returned by date function
+ * 29 Too many parameters given to SETPRM */