C  THIS IS THE FIRST LINE OF ADVENTURE, MAIN MODULE.

      SUBROUTINE MAIN
C  CURRENT LIMITS:
C      20000 WORDS OF MESSAGE TEXT (LINES, LINSIZ).
C       1600 TRAVEL OPTIONS (TRAVEL, TRVSIZ).
C       600 VOCABULARY WORDS (KTAB, ATAB, TABSIZ).
C       250 LOCATIONS (LTEXT, STEXT, KEY, LOCCON, ABB, ATLOC,
C                       LOCSIZ, MAXLOC).
C       150 OBJECTS (PLAC, PLACE, FIXD, FIXED, LINK (TWICE), PTEXT, POINTS,
C                       HOLDER, HLINK, OBJCND, OBJCON, PROP, WEIGHT, MAXOBJ).
C        60 "ACTION" VERBS (ACTSPK, VRBSIZ, VKEY).
C       300 VERB/PREP/OBJ COMBINATIONS (PTAB, PTBSIZ).
C        50 ADJECTIVES (ADJKEY, ADJSIZ)
C       150 MODIFIED NOUNS (ADJTAB, MAXOBJ)
C       400 RANDOM MESSAGES (RTEXT, RTXSIZ).
C        12 DIFFERENT PLAYER CLASSIFICATIONS (CTEXT, CVAL, CLSMAX).
C        20 HINTS, LESS 3 (HINTLC, HINTED, HINTS, HNTSIZ, HNTMIN).
C        35 MAGIC MESSAGES (MTEXT, MAGSIZ).

C  THERE ARE ALSO LIMITS WHICH CANNOT BE EXCEEDED DUE TO THE STRUCTURE OF
C  THE DATABASE.  (E.G., THE VOCABULARY USES N/1000 TO DETERMINE WORD TYPE,
C  SO THERE CAN'T BE MORE THAN 1000 WORDS OF ANY CLASS.)  THESE UPPER
C  LIMITS ARE:
C       1000 NON-SYNONYMOUS VOCABULARY WORDS OF EACH CLASS.  CURRENTLY DEFINED
C       CLASSES ARE:
C               1. MOTION/DIRECTION WORDS (EAST, WEST, UP, JUMP, ETC.)
C               2. NOUNS/OBJECTS (LAMP, KEYS, TROLL, ETC.)
C               3. ACTION VERBS, TRANSITIVE & INTRANSITIVE (TAKE, DROP, KILL, IN
C               4. MISCELLANEOUS WORDS; MOSTLY THINGS OR ACTIONS WHICH GENERATE
C                  FIXED REPLIES (FEE-FIE-FOE-FOO, TREE, CAVE, CURSES)
C               5. PREPOSITIONS, DUPLICATES MANY WORDS IN SECTION 1.
C               6. ADJECTIVES
C               7. CONJUNCTIONS
C       450 LOCATIONS
C       100 OBJECTS WHICH CAN BE USED IN TRAVEL TABLE (PLUS 900 MORE, WHICH CAN'


C  DESCRIPTION OF THE DATABASE FORMAT
C
C
C  THE DATA FILE CONTAINS SEVERAL SECTIONS.  EACH BEGINS WITH A LINE CONTAINING
C  A NUMBER IDENTIFYING THE SECTION, AND ENDS WITH A LINE CONTAINING "-1".
C
C  SECTION 1: LONG FORM DESCRIPTIONS.  EACH LINE CONTAINS A LOCATION NUMBER,
C       A TAB, AND A LINE OF TEXT.  THE SET OF (NECESSARILY ADJACENT) LINES
C       WHOSE NUMBERS ARE X FORM THE LONG DESCRIPTION OF LOCATION X.
C
C  SECTION 2: SHORT FORM DESCRIPTIONS.  SAME FORMAT AS LONG FORM.  NOT ALL
C       PLACES HAVE SHORT DESCRIPTIONS.
C
C  SECTION 3: VOCABULARY.  EACH LINE CONTAINS A NUMBER (N), A TAB, AND A
C       FIVE-LETTER WORD.  CALL M=N/1000.  IF M=0, THEN THE WORD IS A MOTION
C       VERB FOR USE IN TRAVELLING (SEE SECTION 4).  ELSE, IF M=1, THE WORD IS
C       AN OBJECT.  ELSE, IF M=2, THE WORD IS AN ACTION VERB (SUCH AS "CARRY"
C       OR "ATTACK").  ELSE, IF M=3, THE WORD IS A SPECIAL CASE VERB (SUCH AS
C       "DIG") AND N MOD 1000 IS AN INDEX INTO SECTION 6.  OBJECTS FROM 50 TO
C       (CURRENTLY, ANYWAY) 79 ARE CONSIDERED TREASURES (FOR PIRATE, CLOSEOUT).
C
C  SECTION 4: TRAVEL TABLE.  EACH LINE CONTAINS A LOCATION NUMBER (X), A SECOND
C       LOCATION NUMBER (Y), AND A LIST OF MOTION VERBS (SEE SECTION 3).
C       EACH MOTION REPRESENTS A VERB WHICH WILL GO TO Y IF CURRENTLY AT X.
C       Y, IN TURN, IS INTERPRETED AS FOLLOWS.  LET M=Y/1000, N=Y MOD 1000.
C               IF N<=MAXLOC    IT IS THE LOCATION TO GO TO.
C               IF MAXLOC<N<=500   N-MAXLOC IS USED IN A COMPUTED GOTO
C                                       TO A SECTION OF SPECIAL CODE.
C               IF N>500        MESSAGE N-500 FROM SECTION 6 IS PRINTED,
C                                       AND HE STAYS WHEREVER HE IS.
C       MEANWHILE, M SPECIFIES THE CONDITIONS ON THE MOTION.
C               IF M=0          IT'S UNCONDITIONAL.
C               IF 0<M<100      IT IS DONE WITH M% PROBABILITY.
C               IF M=100        UNCONDITIONAL, BUT FORBIDDEN TO DWARVES.
C               IF 100<M<=200   HE MUST BE CARRYING OBJECT M-100.
C               IF 200<M<=300   MUST BE CARRYING OR IN SAME ROOM AS M-200.
C               IF 300<M<=400   PROP(M MOD 100) MUST *NOT* BE 0.
C               IF 400<M<=500   PROP(M MOD 100) MUST *NOT* BE 1.
C               IF 500<M<=600   PROP(M MOD 100) MUST *NOT* BE 2, ETC.
C       IF THE CONDITION (IF ANY) IS NOT MET, THEN THE NEXT *DIFFERENT*
C       "DESTINATION" VALUE IS USED (UNLESS IT FAILS TO MEET *ITS* CONDITIONS,
C       IN WHICH CASE THE NEXT IS FOUND, ETC.).  TYPICALLY, THE NEXT DEST WILL
C       BE FOR ONE OF THE SAME VERBS, SO THAT ITS ONLY USE IS AS THE ALTERNATE
C       DESTINATION FOR THOSE VERBS.  FOR INSTANCE:
C               15      110022  29      31      34      35      23      43
C               15      14      29
C       THIS SAYS THAT, FROM LOC 15, ANY OF THE VERBS 29, 31, ETC., WILL TAKE
C       HIM TO 22 IF HE'S CARRYING OBJECT 10, AND OTHERWISE WILL GO TO 14.
C               11      303008  49
C               11      9       50
C       THIS SAYS THAT, FROM 11, 49 TAKES HIM TO 8 UNLESS PROP(3)=0, IN WHICH
C       CASE HE GOES TO 9.  VERB 50 TAKES HIM TO 9 REGARDLESS OF PROP(3).
C       (SEE DESCRIPTION FOR SECTION 14 FOR A SCHEMATIC OF TABLES.)
C
C  SECTION 5: OBJECT DESCRIPTIONS.  EACH LINE CONTAINS A NUMBER (N), A TAB,
C       AND A MESSAGE.  IF N IS FROM 1 TO MAXOBJ, THE MESSAGE IS THE "INVENTORY"
C       MESSAGE FOR OBJECT N.  OTHERWISE, N SHOULD BE 0000, 1000, 2000, ETC., AN
C       THE MESSAGE SHOULD BE THE DESCRIPTION OF THE PRECEDING OBJECT WHEN ITS
C       PROP VALUE IS N/1000.  THE N/1000 IS USED ONLY TO DISTINGUISH MULTIPLE
C       MESSAGES FROM MULTI-LINE MESSAGES; THE PROP INFO ACTUALLY REQUIRES ALL
C       MESSAGES FOR AN OBJECT TO BE PRESENT AND CONSECUTIVE.  PROPERTIES WHICH
C       PRODUCE NO MESSAGE SHOULD BE GIVEN THE MESSAGE ">$<".  NOTE THAT
C       OBJECTS WITH N>100 CANNOT BE USED FOR CONDITIONAL MOTIONS IN
C       TRAVEL TABLE.
C
C  SECTION 6: ARBITRARY MESSAGES.  SAME FORMAT AS SECTIONS 1, 2, AND 5, EXCEPT
C       THE NUMBERS BEAR NO RELATION TO ANYTHING (EXCEPT FOR SPECIAL VERBS
C       IN SECTION 3).
C
C  SECTION 7: CONTAINS LOTS OF OBJECT INFO:
C       (1) OBJECT LOCATIONS & WEIGHTS.  EACH LINE CONTAINS AN OBJECT NUMBER
C       AND ITS INITIAL LOCATION (ZERO (OR OMITTED) IF NONE).  IF THE OBJECT IS
C       IMMOVABLE, THE LOCATION IS FOLLOWED BY A "-1".  IF IT HAS TWO LOCATIONS
C       (E.G. THE GRATE) THE FIRST LOCATION IS FOLLOWED WITH THE SECOND, AND
C       THE OBJECT IS ASSUMED TO BE IMMOVABLE.  IF THE OBJECT IS MOVABLE, IT
C       HAS A THIRD NUMBER WHICH IS ITS RELATIVE WEIGHT.
C       (2) DEFAULT OBJECT NAMES. TEN CHARACTER MAXIMUM, TO PERMIT PRINTING
C       OBJECT NAMES WHEN HERO SAYS 'TAKE ALL' OR SUCH.
C       (3) POINTS.  OBJECT NUMBER, A SCORE
C       VALUE, A PROP VALUE, AND A LOCATION NUMBER.  THE SCORE IS
C       FOR LEAVING IT AT THE NAMED LOCATION WITH THE RIGHT PROP VALUE.
C       SCORES ARE ASSIGNED ON A DIFFICULTY SCALE OF 1-5 (1 IS
C       FOR EASY TREASURES; 5 IS FOR REAL HARD ONES), AND ARE MULTIPLIED
C       BY SOME APPROPRIATE FACTOR AT SCORING TIME.
C
C  SECTION 8: ACTION DEFAULTS.  EACH LINE CONTAINS AN "ACTION-VERB" NUMBER AND
C       THE INDEX (IN SECTION 6) OF THE DEFAULT MESSAGE FOR THE VERB.
C
C  SECTION 9: LIQUID ASSETS, ETC.  EACH LINE CONTAINS A NUMBER (N) AND UP TO 20
C       LOCATION NUMBERS.  BIT N (WHERE 0 IS THE UNITS BIT) IS SET IN LOCCON(LOC
C       FOR EACH LOC GIVEN.  THE COND BITS CURRENTLY ASSIGNED ARE:
C               0       LIGHT
C               1       IF BIT 3 IS ON: ON FOR OIL, OFF FOR WATER
C               2       IF BIT 3 IS ON: ON FOR WINE, OFF FOR WATER & OIL
C               3       LIQUID ASSET, SEE BITS 1 & 2
C               4       PIRATE DOESN'T GO HERE UNLESS FOLLOWING PLAYER
C               5       ALL LOCATIONS IN EITHER 'PORTAL';  I.E., NOT OUTSIDE
C                       CAVE, BUT NOT FAR IN
C               6       ALL LOCATIONS OUTSIDE THE CAVE
C       OTHER BITS ARE USED TO INDICATE AREAS OF INTEREST TO "HINT" ROUTINES:
C               7       LOST IN MAZE
C               8       PONDERING DARK ROOM
C               9       AT WITT'S END
C               10      TRYING TO EXTRACT SWORD
C               11      TRYING TO GO UP SLIDE
C               12      TRYING TO GET INTO CAVE VIA SEA ENTRANCE
C               13      TRYING TO FIND CAVE (ANY ENTRANCE)
C               14      TRYING TO CATCH BIRD
C               15      TRYING TO GET OVER THE RAINBOW
C               16      STYMIED BY DOG
C               17      TRYING TO DEAL WITH SNAKE
C       LOCCON(LOC) IS SET TO 2, OVERRIDING ALL OTHER BITS, IF LOC HAS FORCED
C       MOTION.
C
C  SECTION 10: CLASS MESSAGES.  EACH LINE CONTAINS A NUMBER (N), A TAB, AND A
C       MESSAGE DESCRIBING A CLASSIFICATION OF PLAYER.  THE SCORING SECTION
C       SELECTS THE APPROPRIATE MESSAGE, WHERE EACH MESSAGE IS CONSIDERED TO
C       APPLY TO PLAYERS WHOSE SCORES ARE HIGHER THAN THE PREVIOUS N BUT NOT
C       HIGHER THAN THIS N.  NOTE THAT THESE SCORES PROBABLY CHANGE WITH EVERY
C       MODIFICATION (AND PARTICULARLY EXPANSION) OF THE PROGRAM.
C
C  SECTION 11: HINTS.  EACH LINE CONTAINS A HINT NUMBER (CORRESPONDING TO A
C       COND BIT, SEE SECTION 9), THE NUMBER OF TURNS HE MUST BE AT THE RIGHT
C       LOC(S) BEFORE TRIGGERING THE HINT, THE POINTS DEDUCTED FOR TAKING THE
C       HINT, THE MESSAGE NUMBER (SECTION 6) OF THE QUESTION, AND THE MESSAGE
C       NUMBER OF THE HINT.  THESE VALUES ARE STASHED IN THE "HINTS" ARRAY.
C       HNTMAX IS SET TO THE MAX HINT NUMBER (<= HNTSIZ).  NUMBERS 1-6 ARE
C       UNUSABLE SINCE COND BITS ARE OTHERWISE ASSIGNED, SO 2 IS USED TO
C       REMEMBER IF HE'S READ THE CLUE IN THE REPOSITORY, AND 3 IS USED TO
C       REMEMBER WHETHER HE ASKED FOR INSTRUCTIONS (GETS MORE TURNS, BUT LOSES
C       POINTS).  HNTMIN IS SET TO THE NUMBER OF THE FIRST USABLE HINT.
C
C  SECTION 12: MAGIC MESSAGES. IDENTICAL TO SECTION 6 EXCEPT PUT IN A SEPARATE
C       SECTION FOR EASIER REFERENCE.  MAGIC MESSAGES ARE USED BY THE STARTUP,
C       MAINTENANCE MODE, AND RELATED ROUTINES.
C
C  SECTION 14: PREPOSITION TABLE.  EACH LINE CONTAINS A VERB, A PREPOSITION
C       AND VALID OBJECTS FOR THAT VERB/PREP COMBINATION.  THEY ARE CONVERTED
C       INTO TWO TABLES SIMILAR IN FORMAT TO THE TRAVEL TABLE.  THE FIRST
C       TABLE, VKEY, HAS ONE ENTRY PER VERB.  A ZERO ENTRY INDICATES NO
C       PREPOSITION IS VALID WITH THAT VERB.  A NON-ZERO ENTRY POINTS TO THE
C       BEGINNING OF THE PREP/OBJ LIST FOR THAT VERB.  THE POSITION OF THE
C       ENTRY IN VKEY CORRESPONDS TO THE VERB NUMBER.  THE PREP/OBJ LIST,
C       PTAB, FOR A GIVEN VERB CONSISTS OF A SERIES OF ONE-WORD ENTRIES
C       DELIMITED BY A NEGATIVE ENTRY.  EACH WORD CONTAINS THE PREPOSITION
C       NUMBER TIMES 1000 PLUS THE NUMBER OF A VALID OBJECT.  A SCHEMATIC
C       FOLLOWS.  ENTRIES IN VKEY ARE REPRESENTED BY V1, V2, ... VN.
C       ENTRIES IN PTAB ARE REPRESENTED BY P1, P2, ..., PN (PREPOSITIONS),
C       AND OB1, OB2,..., OBN (OBJECTS).
C
C           I   VKEY(I)         PTAB(J) J
C           -   -------         ------- -
C           1.  V1==========>>  P1,OB1  1.
C                               P1,OB2  2.
C                               P1,OB3  3.
C                               P1,OB4  4.
C                               P1,OB5  5.
C                               P2,OB1  6.
C                               P2,OB2  7.
C                               P3,OB1  8.
C                               P3,OB2  9.
C                               P3,OB3  10.
C                              -P3,OB4  11.
C           2.  V2==========>>  P1,OB1  12.
C                               P1,OB2  13.
C                               P2,OB1  14.
C                              -P3,OB1  15.
C           3.  0  (THE VERB CORRESPONDING TO THIS POSITION TAKES NO PREPOSITION
C           4.  V3==========>>  P1,OB1  16.
C                              -P2,OB1  17.
C
C SECTION 15: OBJECT ATTRIBUTES.  EACH LINE CONTAINS A BIT NUMBER AND
C       UP TO 20 OBJECT NUMBERS.  BIT N (WHERE ZERO IS THE UNITS BIT) IS SET
C       IN OBJCON(OBJ) FOR EACH OBJECT GIVEN.  THE BITS CURRENTLY ASSIGNED
C       ARE:
C               1       THE OBJ CAN BE OPENED/CLOSED. (DOORS, GRATE, CLAM, ETC.)
C               2       THE OBJ IS CURRENTLY OPEN.
C               3       IT HAS A LOCK. (GRATE, CHAIN, ELFIN DOOR, ETC.)
C               4       IT IS CURRENTLY LOCKED.
C               5       FLAMMABLE.  (IT WILL BURN IF IGNITED.)
C               6       IT IS CURRENTLY BURNING.
C               7       EDIBLE.  FOOD, MUSHROOMS, ETC.
C               8       PRINTED MATERIAL, ANYTHING READABLE
C               9       A LIVING BEASTIE, E.G., DWARF, DOG, WUMPUS, ETC.
C               10      DEAD (KILLED) BEASTIE: WUMPUS, DRAGON, SLEEPING DOG
C               11      CAN BE WORN: CROWN, SHOES, CLOAK, JEWELS
C               12      IS CURRENTLY BEING WORN
C               13      REQUIRES PLURAL RESPONSES (SHOES, COINS, ETC.)
C               14      TREASURE.
C               15      CONTAINER.
C               16      OBJECT IS "SMALL". (CAN FIT INTO SACK OR CHEST)
C               17      CONTAINER IS OPAQUE -- CONTENTS ARE NOT VISIBLE UNLESS
C                       CONTAINER IS OPEN.
C
C  SECTION 16: ADJECTIVE/NOUN LIST.  EACH VALID ADJECTIVE IS FOLLOWED BY
C       ALL NOUNS WHICH IT MAY MODIFY.
C
C  SECTION 0: END OF DATABASE.

       IMPLICIT INTEGER(A-Z)
       LOGICAL DSEEN,BLKLIN,HINTED,YES,START,TERSE,ISWIZ,LOGOUT
       LOGICAL WZDARK,KILLED,RDFLAG,LIVING
      INTEGER*4 BITS,TRAVEL,POINTS,OBJCND,LOCCON,STEXT,RTEXT,MTEXT
      INTEGER*4 LINUSE,KK,LINSIZ,K1,PTAB,WKDAY,WKEND,HOLID,LTEXT
      INTEGER*4 PTEXT,OBJCON,J12,JL1,JL2,JKK,JK1,LINES,JNEW,RETN,CTEXT
      DOUBLE PRECISION DTK(9),ATAB,NTXT,DJJ,DK,DKK,DL,DLL
      DOUBLE PRECISION VTXT,OTXT,IOTXT,MAGIC,TXT

      COMMON/IZWIZ/ISWIZ
      INTEGER*4 MESSGS
      COMMON/LNKCOM/ACTIVE(32),USER(15,32),MESSGS(32),MONITO(32),
     1 TEXT(70,32)
      LOGICAL ACTIVE
       COMMON /ADJCOM/ ADJKEY(50),ADJTAB(150),ADJSIZ
       COMMON /ALLCOM/ NTXT(150,2)
       COMMON /BITCOM/ OPENBT,LOCKBT,BURNBT,WEARBT
       COMMON /BLKCOM/ BLKLIN
       COMMON /CONCOM/ LOCCON(250),OBJCON(150)
       COMMON /DIECOM/ NUMDIE,MAXDIE,TURNS
       COMMON /DWFCOM/ DWARF,KNIFE,KNFLOC,DFLAG,DSEEN(6),DLOC(6),
     1  ODLOC(6),DWFMAX
       COMMON /HLDCOM/ HOLDER(150),HLINK(150)
       COMMON /HNTCOM/ HINTLC(20),HINTED(20),HINTS(20,4),HNTSIZ,HNTMIN
       COMMON /LIQCOM/ BOTTLE,CASK,WATER,OIL,WINE,LIQTYP(5)
       COMMON /LOCCOM/ LOC,OLDLOC,OLDLC2,NEWLOC,MAXLOC
       COMMON /MNECOM/ BACK,CAVE,DPRSSN,ENTRNC,EXIT,GO,LOOK,NULL,
     1 AXE,BEAR,BOAT,BOOK,BOOK2,BOOTH,CARVNG,CHASM,CHASM2,DOOR,GNOME,
     2 GRATE,LAMP,PDOOR,PLANT,PLANT2,ROCKS,ROD,ROD2,SAFE,
     3 TDOOR,TDOOR2,TROLL,TROLL2,EMRALD,SPICES,
     4 FIND,YELL,INVENT,LEAVE,POUR,SAY,TAKE,THROW,
     5 KILLED,IWEST,PHUCE(2,4),TK(20)

       COMMON /LTXCOM/ LTEXT(250),STEXT(250),KEY(250),ABB(250),LOCSIZ
       COMMON /OBJCOM/ PLAC(150),FIXD(150),WEIGHT(150),PROP(150),
     1          POINTS(150)
       COMMON /PLACOM/ ATLOC(250),LINK(300),PLACE(150),
     1          FIXED(150),MAXOBJ
       COMMON /PRPCOM/ VKEY(60),PTAB(300),VKYSIZ,PTBSIZ
       COMMON /TRVCOM/ TRAVEL(1600)
       COMMON /TXTCOM/ LINES(25000),RTEXT(400),PTEXT(150),MTEXT(45)
       COMMON /UTXCOM/ TXT(35,2),WDX
       COMMON /VOCCOM/ KTAB(600),ATAB(600),TABSIZ
       COMMON /WIZCOM/ WKDAY,WKEND,HOLID,HBEGIN,HEND,HNAME,
     1  SHORT,MAGIC,MAGNM,LATNCY,SAVED,SAVET,SETUP
       COMMON /WRDCOM/ VERBS(45),VTXT(45,2),VRBX,OBJS(45),OTXT(45,2),
     1  OBJX,IOBJS(15),IOTXT(15,2),IOBX,PREP,WORDS(45)

       DIMENSION OBJCND(150),ACTSPK(60),CTEXT(12),CVAL(12)
       DIMENSION HNAME(10)

       LOGICAL AJAR,AT,ATHAND,BITSET,BLIND,CLOSED,CLOSNG,
     1  DARK,DEAD,DEMO,EDIBLE,ENCLSD,FORCED,
     2  GAVEUP,HERE,HINGED,HOLDNG,INSIDE,LMWARN,LOCKS,OUTSID,OPAQUE,
     3  PANIC,PCT,PLURAL,PORTAL,PRINTD,SCORNG,SMALL,
     4  TOTING,TREASR,LOCKED,VESSEL,WEARNG,WORN,YEA,
     5  YESM

       DATA LINSIZ/25000/,TRVSIZ/1600/,TABSIZ/600/,LOCSIZ/250/,
     1  VRBSIZ/60/,RTXSIZ/400/,CLSMAX/12/,HNTSIZ/20/,MAGSIZ/45/,
     2  MAXOBJ/150/,MAXLOC/300/,HNTMIN/7/,PTBSIZ/300/,ADJSIZ/50/,
     3  VKYSIZ/60/,SETUP/0/,BLKLIN/.TRUE./,DWFMAX/6/,ISWIZ/.FALSE./

      DATA OBJCND/150*0/,LINUSE/0/
C  PHUCE CONSISTS OF FOUR PAIRS OF ORIGIN/DESTINATION LOCATIONS FROM/TO
C  WHICH ONE IS TRANSPORTED ON UTTERING THE ELFIN CURSE AT THE TINY
C  DOOR.  HE CAN GO FROM BIG TO SMALL OR SMALL TO BIG, ON EITHER SIDE OF
C  THE DOOR.
       DATA PHUCE/158,160,160,158,167,166,166,167/
C       DATA PHROG/'PH','RO','GS'/

C  BITS(N) IS A ONE-BIT IN POSITION N, WHERE THE RIGHTMOST BIT IS BIT ZERO.
C       DATA BITS/
C     1  1,2,4,8,16,32,64,128,256,512,1024,2048,
C     2  :10000,:20000,:40000,
C     3  :100000,:200000,:400000,
C     4  :1000000,:2000000,:4000000,
C     5  :10000000,:20000000,:40000000,
C     6  :100000000,:200000000,:400000000,
C     7  :1000000000,:2000000000,:4000000000,
C     8  :10000000000,:20000000000,:40000000000,
C     9  :100000000000,:200000000000,:400000000000/

       DATA DEADBT,OPENBT,LOCKBT,BURNBT,WEARBT /10,2,4,6,12/
C  STATEMENT FUNCTIONS
C
C
C  AJAR(OBJ     = TRUE IF THE OBJECT IS OPEN
C  AT(OBJ)      = TRUE IF ON EITHER SIDE OF TWO-PLACED OBJECT
C  ATHAND(OBJ)  = TRUE IF OBJECT IS HERE AND NOT IN CLOSED CONTAINER.
C  BITSET(COND,L,N) = TRUE IF COND(L) HAS BIT N SET (BIT 0 IS UNITS BIT)
C  BLIND(DUMMY) = TRUE IF HERO CAN'T SEE (TOO DARK OR GLAREY)
C  DARK(DUMMY)  = TRUE IF LOCATION "LOC" IS DARK
C  DEAD(OBJ)    = TRUE IF CRITTER IS KILLED (OR IN ENCHANTED SLEEP)
C  FORCED(LOC)  = TRUE IF LOC MOVES WITHOUT ASKING FOR INPUT (COND=2)
C  HERE(OBJ)    = TRUE IF THE OBJ IS AT "LOC" (OR IS BEING CARRIED)
C  HINGED(OBJ)  = TRUE IF OBJECT CAN BE OPENED/SHUT.
C  INSIDE(LOC)  = TRUE IF LOCATION IS WELL WITHIN THE CAVE
C  LIQ(DUMMY)   = OBJECT NUMBER OF LIQUID IN BOTTLE
C  LIQLOC(LOC)  = OBJECT NUMBER OF LIQUID (IF ANY) AT LOC
C  LIVING(OBJ)  = TRUE IF OBJ IS SOME SORT OF CRITTER
C  LOCKED(OBJ)  = TRUE IF OBJECT IS LOCKED. (NEED NOT HAVE A LOCK,
C                  E.G., RUSTY DOOR)
C  LOCKS(OBJ)   = TRUE IF OBJECT HAS A LOCK.
C  OPAQUE(OBJ)  = TRUE IF CONTAINER IS NOT TRANSPARENT (SACK, CHEST)
C                 TRANSPARENT OBJS: BOTTLE(GLASS), CAGE(WICKER)
C  OUTSID(LOC)  = TRUE IF LOCATION IS OUTSIDE THE CAVE
C  PCT(N)       = TRUE N% OF THE TIME (N INTEGER FROM 0 TO 100)
C  PLURAL(OBJ)  = TRUE IF IT IS A PLURAL OBJ (SHOES, KEYS, ETC.)
C  PORTAL(LOC)  = TRUE IS LOCATION IS IN CAVE "ENTRANCE"
C  PRINTD(OBJ)  = TRUE IF OBJECT CAN BE READ.
C  SMALL(OBJ)   = TRUE IF OBJ FITS INTO SACK
C  TOTING(OBJ)  = TRUE IF THE OBJ IS BEING CARRIED
C  TREASR(OBJ)  = TRUE IF OBJECT IS A TREASURE
C  VESSEL(OBJ)  = TRUE IF OBJECT IS A CONTAINER
C  WEARNG(OBJ)  = TRUE IF OBJECT IS BEING WORN
C  WORN(OBJ)    = TRUE IF THE OBJECT CAN BE WORN
C
C  CLOSED SAYS WHETHER WE'RE ALL THE WAY CLOSED
C  CLOSNG SAYS WHETHER ITS CLOSING TIME YET
C  DEMO IS TRUE IF THIS IS A PRIME-TIME DEMONSTRATION GAME
C  GAVEUP SAYS WHETHER HE EXITED VIA "QUIT"
C  LMWARN SAYS WHETHER HE'S BEEN WARNED ABOUT LAMP GOING DIM
C  PANIC SAYS WHETHER HE'S FOUND OUT HE'S TRAPPED IN THE CAVE
C  SCORNG INDICATES TO THE RATING ROUTINE WHETHER WE'RE DOING A "SCORE" COMMAND
C  WZDARK SAYS WHETHER THE LOC HE'S LEAVING WAS DARK
C  YEA IS RANDOM YES/NO REPLY



       IF(SETUP.NE.0)GOTO 1200
       PRINT 1000
1000    FORMAT(' INITIALISING...')

      DO 10 I=1,32
10    ACTIVE(I)=.FALSE.
C  CLEAR OUT THE VARIOUS TEXT-POINTER ARRAYS.  ALL TEXT IS STORED IN ARRAY
C  LINES; EACH LINE IS PRECEDED BY A WORD POINTING TO THE NEXT POINTER (I.E.
C  THE WORD FOLLOWING THE END OF THE LINE).  THE POINTER IS NEGATIVE IF THIS IS
C  FIRST LINE OF A MESSAGE.  THE TEXT-POINTER ARRAYS CONTAIN INDICES OF
C  POINTER-WORDS IN LINES.  STEXT(N) IS SHORT DESCRIPTION OF LOCATION N.
C  LTEXT(N) IS LONG DESCRIPTION.  PTEXT(N) POINTS TO MESSAGE FOR PROP(  PROPN)=0
C  SUCCESSIVE PROP MESSAGES ARE FOUND BY CHASING POINTERS.  RTEXT CONTAINS
C  SECTION 6'S STUFF.  CTEXT(N) POINTS TO A PLAYER-CLASS MESSAGE.  MTEXT IS FOR
C  SECTION 12.  WE ALSO CLEAR COND.  SEE DESCRIPTION OF SECTION 9 FOR DETAILS.

       DO 1001 I=1,MAXLOC
       IF(I.LE.MAXOBJ)PTEXT(I)=0
       IF(I.LE.RTXSIZ)RTEXT(I)=0
       IF(I.LE.CLSMAX)CTEXT(I)=0
       IF(I.LE.MAGSIZ)MTEXT(I)=0
       IF(I.GT.LOCSIZ)GOTO 1001
       STEXT(I)=0
       LTEXT(I)=0
       LOCCON(I)=0
1001    CONTINUE

      CALL SRCH$$(1,'ADVE.BASE',9,1,TYPE,CODE)
       SETUP=1
       LINUSE=1
       TRVS=1
       PTBS=1
       ATBS=1
       CLSSES=1

C  START NEW DATA SECTION.  SECT IS THE SECTION NUMBER.

1002    READ(5,1003)SECT
1003    FORMAT(I8)
       PRINT 1015,SECT
1015   FORMAT (' READING TABLE ',I2,'...')
       OLDLOC=-1
       GOTO(1190,1004,1004,1040,1030,1004,1004,1050,1060,1070,1004,
     1    1080,1004,0999,1100,1120,1140),(SECT+1)
C             (0)  (1)  (2)  (3)  (4)  (5)  (6)  (7)  (8)  (9)  (10)
C            (11) (12) (13) (14) (15) (16)
999     CALL BUG(9)

C  SECTIONS 1, 2, 5, 6, 10, 12.  READ MESSAGES AND SET UP POINTERS.

1004  JL1=LINUSE+1
      JL2=LINUSE+18
        READ(5,1005)LOC,(LINES(J12),J12=JL1,JL2),KK
1005  FORMAT(I8,19A4)
       IF(KK.EQ.'   ')GOTO 1017
       PRINT 1016,LOC
1016    FORMAT (1X,'LINE FOR LOCN ',I4,' TOO LONG.')
       CALL BUG(0)

1017    IF(LOC.EQ.-1)GOTO 1002
       DO 1006 K=1,18
       JKK=LINUSE+19-K
       IF(LINES(JKK).NE.' ')GOTO 1007
1006    CONTINUE
       IF(LOC.EQ.0)GOTO 1004
C  ABOVE KLUGE IS TO AVOID F40 BUG IF CRLF BROKEN ACROSS RECORD BOUNDARY
       CALL BUG(1)

1007  JL1=LINUSE+1
        DO 1008 JK1=JL1,JKK
1008  LINES(JK1)=XOR(LINES(JK1),'CLYD')
       LINES(LINUSE)=JKK+1
       IF(LOC.EQ.OLDLOC)GOTO 1020
       IF(LOC.GT.OLDLOC.OR.SECT.EQ.5)GOTO 1019
       PRINT 1018,LOC,SECT
1018    FORMAT (/' LINE ',I3,' OUT OF ORDER IN SECTION ',I2)
       CALL BUG(10)

1019    LINES(LINUSE)=-LINES(LINUSE)
       IF(SECT.EQ.12)GOTO 1013
       IF(SECT.EQ.10)GOTO 1012
       IF(SECT.EQ.6)GOTO 1011
       IF(SECT.EQ.5)GOTO 1010
       IF(SECT.EQ.1)GOTO 1009

       STEXT(LOC)=LINUSE
       GOTO 1020

1009    LTEXT(LOC)=LINUSE
       GOTO 1020

1010    IF(LOC.GT.0.AND.LOC.LE.MAXOBJ)PTEXT(LOC)=LINUSE
       GOTO 1020

1011    IF(LOC.GT.RTXSIZ)CALL BUG(6)
       RTEXT(LOC)=LINUSE
       GOTO 1020

1012    CTEXT(CLSSES)=LINUSE
       CVAL(CLSSES)=LOC
       CLSSES=CLSSES+1
       GOTO 1020

1013    IF(LOC.GT.MAGSIZ)CALL BUG(6)
       MTEXT(LOC)=LINUSE

1020    LINUSE=JKK+1
       LINES(LINUSE)=-1
       OLDLOC=LOC
       IF(LINUSE+18.GT.LINSIZ)CALL BUG(2)
       GOTO 1004

C  THE STUFF FOR SECTION 4 IS ENCODED HERE.  EACH "FROM-LOCATION" GETS A
C  CONTIGUOUS SECTION OF THE "TRAVEL" ARRAY.  EACH ENTRY IN TRAVEL IS
C  NEWLOC*1000 + KEYWORD (FROM SECTION 3, MOTION VERBS), AND IS NEGATED IF
C  THIS IS THE LAST ENTRY FOR THIS LOCATION.  KEY(N) IS THE INDEX IN TRAVEL
C  OF THE FIRST OPTION AT LOCATION N.

1030    READ(5,1031)LOC,JNEW,(DTK(I),I=1,8)
1031  FORMAT(2I8,8(A6,2X))
       IF(LOC.EQ.0)GOTO 1030
C  ABOVE KLUGE IS TO AVOID AFOREMENTIONED F40 BUG
       IF(LOC.EQ.-1)GOTO 1002
       IF(LOC.GE.OLDLOC)GOTO 1032
       PRINT 1018,LOC,SECT
       CALL BUG(10)

1032    IF(KEY(LOC).NE.0)GOTO 1033
       KEY(LOC)=TRVS
       GOTO 1035

1033    TRAVEL(TRVS-1)=-TRAVEL(TRVS-1)
1035    DO 1037 L=1,8
       IF(DTK(L).EQ.'        ')GOTO 1039
       K=VOCABX(DTK(L),-1)
       TRAVEL(TRVS)=JNEW*1000+K
       TRVS=TRVS+1
       IF(TRVS.EQ.TRVSIZ)CALL BUG(3)
1037    CONTINUE
1039    TRAVEL(TRVS-1)=-TRAVEL(TRVS-1)
       GOTO 1030

C  HERE WE READ IN THE VOCABULARY.  KTAB(N) IS THE WORD NUMBER, ATAB(N) IS
C  THE CORRESPONDING WORD.  THE -1 AT THE END OF SECTION 3 IS LEFT IN KTAB
C  AS AN END-MARKER.  THE WORDS ARE GIVEN A MINIMAL HASH TO MAKE READING THE
C  CORE-IMAGE HARDER.  NOTE THAT '/7-08' HAD BETTER NOT BE IN THE LIST, SINCE
C  IT COULD HASH TO -1.

1040    DO 1042 TABNDX=1,TABSIZ
1043    READ(5,1041)KTAB(TABNDX),ATAB(TABNDX)
1041  FORMAT(I8,A6)
       IF(KTAB(TABNDX).EQ.0)GOTO 1043
C  ABOVE KLUGE IS TO AVOID AFOREMENTIONED F40 BUG
       IF(KTAB(TABNDX).EQ.-1)GOTO 1002
1042  CONTINUE
       CALL BUG(4)

C  READ IN THE INITIAL LOCATIONS FOR EACH OBJECT.  ALSO THE IMMOVABILITY INFO.
C  PLAC CONTAINS INITIAL LOCATIONS OF OBJECTS.  FIXD IS -1 FOR IMMOVABLE
C  OBJECTS (INCLUDING THE SNAKE), OR = SECOND LOC FOR TWO-PLACED OBJECTS.
C  WEIGHT CONTAINS THE HEAVINESS OF EACH OBJ, ON A SCALE OF 1-10.

1050    READ(5,1052) OBJ,J,K,KK,DL,DLL,(TK(I),I=1,3)
1052  FORMAT(4I8,2(A6,2X),3I8)
       IF(OBJ.EQ.-1)GOTO 1002
       IF(OBJ.LE.0.OR.OBJ.GT.MAXOBJ)CALL BUG(17)
       PLAC(OBJ)=J
       FIXD(OBJ)=K
       WEIGHT(OBJ)=KK
C  READ DEFAULT OBJECT NAMES.  FOR USE IN 'TAKE ALL' COMMANDS.
       NTXT(OBJ,1)=DL
       NTXT(OBJ,2)=DLL
C  READ POINT VALUES FOR TREASURES.
       K=1
       IF(TK(3).LT.0)K=-1
       POINTS(OBJ)= (TK(1)*1000000*K) + (TK(2)*1000*K) + TK(3)
       GOTO 1050

C  READ DEFAULT MESSAGE NUMBERS FOR ACTION VERBS, STORE IN ACTSPK.

1060    READ(5,1061)VERB,J
1061    FORMAT(10I8)
       IF(VERB.EQ.-1)GOTO 1002
       ACTSPK(VERB)=J
       GOTO 1060

C  READ INFO ABOUT AVAILABLE LIQUIDS AND OTHER CONDITIONS, STORE IN COND.

1070    READ(5,1061)K,(TK(I),I=1,9)
       IF(K.EQ.-1)GOTO 1002
       DO 1071 I=1,20
       LOC=TK(I)
       IF(LOC.EQ.0)GOTO 1070
      IF(BITSET(LOCCON(LOC),K))CALL BUG(8)
1071    LOCCON(LOC)=LOCCON(LOC)+BITS(K)
       GOTO 1070

C  READ DATA FOR HINTS.

1080    HNTMAX=0
1081    READ(5,1061)K,(TK(I),I=1,9)
       IF(K.EQ.-1)GOTO 1002
       IF(K.EQ.0)GOTO 1081
       IF(K.LT.0.OR.K.GT.HNTSIZ)CALL BUG(7)
       DO 1083 I=1,4
1083    HINTS(K,I)=TK(I)
       HNTMAX=MAX0(HNTMAX,K)
       GOTO 1081

C  SECTION 14 IS THE PREPOSITION TABLE.
1100    READ(5,1101)DK,DKK,(DTK(I),I=1,8)
1101  FORMAT(10(A6,2X))
       IF(DK.EQ.0)GOTO 1100
C  ABOVE KLUGE IS TO AVOID AFOREMENTIONED F40 BUG
       IF(DK.EQ.'-1      ')GOTO 1002
       VERB=VAL(VOCABX(DK,-4))
       DJJ=DK
       IF(VERB.EQ.-1)GOTO 1106
       PREP=VAL(VOCABX(DKK,-6))
       DJJ=DKK
       IF(PREP.EQ.-1)GOTO 1106

       IF(VKEY(VERB).NE.0)GOTO 1104
       VKEY(VERB)=PTBS
       GOTO 1105

1104    PTAB(PTBS-1)=-PTAB(PTBS-1)
1105    DO 1110 L=1,8
       IF(DTK(L).EQ.'        ')GOTO 1111
       K=VAL(VOCABX(DTK(L),-3))
       IF(K.NE.-1)GOTO 1108
       K=999
       IF(L.EQ.1.AND.DTK(1).EQ.'ANY     ')GOTO 1108
       DJJ=DTK(L)
       GO TO 1106

1108    PTAB(PTBS)=PREP*1000+K
       PTBS=PTBS+1
       IF(PTBS.EQ.PTBSIZ)CALL BUG(15)
1110    CONTINUE
1111    PTAB(PTBS-1)=-PTAB(PTBS-1)
       GOTO 1100

C only come here via "GO TO 1106", never should drop in.
1106    PRINT 1107,DJJ
1107    FORMAT(/' UNRECOGNIZED WORD "',A6,'" IN PREP/OBJ TABLE.')
       CALL BUG(14)

C  READ CONDITION BITS FOR OBJECTS.  KK IS THE BIT; TK(I), THE OBJ LIST.

1120    READ(5,1061)IKK,(TK(I),I=1,9)
       IF(IKK.EQ.-1)GOTO 1002
       DO 1125 I=1,9
       OBJ=TK(I)
       IF(OBJ.EQ.0)GOTO 1120
       IF(OBJ.LE.0.OR.OBJ.GT.MAXOBJ)CALL BUG(17)
      IF(.NOT.BITSET(OBJCND(OBJ),IKK))GOTO 1125
      WRITE(1,101)OBJ,IKK
101   FORMAT('BIT SET TWICE OBJ=',I5,'  BIT= ',I5)
      CALL BUG(16)
1125    OBJCND(OBJ)=OBJCND(OBJ)+BITS(IKK)
       GOTO 1120

C  SECTION 17 IS THE ADJECTIVE TABLE.
1140    READ(5,1141)DK,(DTK(I),I=1,9)
1141    FORMAT(10(A6,2X))
       IF(DK.EQ.0)GOTO 1140
C  ABOVE KLUGE IS TO AVOID AFOREMENTIONED F40 BUG
       IF(DK.EQ.'-1      ')GOTO 1002
       ADJ=VOCABX(DK,-7)
       DJJ=DK
       IF(ADJ.EQ.-1.OR.CLASS(ADJ).NE.6)GOTO 1148
       ADJ=VAL(ADJ)
       IF(ADJKEY(ADJ).NE.0)GOTO 1142
       ADJKEY(ADJ)=ATBS
       GOTO 1143

1142    ADJTAB(ATBS-1)=-ADJTAB(ATBS-1)
1143    DO 1145 L=1,9
       IF(DTK(L).EQ.'        ')GOTO 1146
       DJJ=DTK(L)
       K=VOCABX(DTK(L),-3)
       IF(K.EQ.-1.OR.CLASS(K).NE.2)GOTO 1148
       ADJTAB(ATBS)=VAL(K)
       ATBS=ATBS+1
       IF(ATBS.EQ.MAXOBJ)CALL BUG(18)
1145    CONTINUE
1146    ADJTAB(ATBS-1)=-ADJTAB(ATBS-1)
       GOTO 1140

1148    PRINT 1149,DJJ
1149    FORMAT(/' UNRECOGNIZED WORD "',A6,'" IN ADJECTIVE TABLE.')
       CALL BUG(13)


C  EVERYTHING IS READ!  NOW FINISH CONSTRUCTING INTERNAL DATA FORMAT.
C  DEFINE SOME HANDY MNEMONICS.  THESE CORRESPOND TO OBJECT NUMBERS.
C  (INCLUDES TREASURES.)

1190  CALL CLOS$A(1)
        ANVIL=VOCABX('ANVIL   ',2)
       AXE=VOCABX('AXE     ',2)
       BATTER=VOCABX('BATTER  ',2)
       BEAR=VOCABX('BEAR    ',2)
       BEES=VOCABX('BEES    ',2)
       BILLBD=VOCABX('BILLBO  ',2)
       BIRD=VOCABX('BIRD    ',2)
       BOAT=VOCABX('BOAT    ',2)
       BOOK=VOCABX('BOOK    ',2)
       BOOK2=BOOK+1
       BOOTH=VOCABX('BOOTH   ',2)
       BOTTLE=VOCABX('BOTTLE  ',2)
       BRUSH=VOCABX('BRUSH   ',2)
       CAGE=VOCABX('CAGE    ',2)
       CAKES=VOCABX('CAKES   ',2)
       CARVNG=VOCABX('CARVIN  ',2)
       CASK=VOCABX('CASK    ',2)
       CHAIN=VOCABX('CHAIN   ',2)
       CHASM=VOCABX('CHASM   ',2)
       CHASM2=CHASM+1
       CHEST=VOCABX('CHEST   ',2)
       CLAM=VOCABX('CLAM    ',2)
       CLOAK=VOCABX('CLOAK   ',2)
       COINS=VOCABX('COINS   ',2)
       CROWN=VOCABX('CROWN   ',2)
       DOG=VOCABX('DOG     ',2)
       DOOR=VOCABX('DOOR    ',2)
       DRAGON=VOCABX('DRAGON  ',2)
       DWARF=VOCABX('DWARF   ',2)
       EGGS=VOCABX('EGGS    ',2)
       EMRALD=VOCABX('EMERAL  ',2)
       FISSUR=VOCABX('FISSUR  ',2)
       FLOWER=VOCABX('FLOWER  ',2)
      FLY=VOCABX('FLY     ',2)
       FOOD=VOCABX('FOOD    ',2)
       GNOME=VOCABX('GNOME   ',2)
       GRAIL=VOCABX('GRAIL   ',2)
       GRATE=VOCABX('GRATE   ',2)
       HIVE=VOCABX('HIVE    ',2)
       HONEY=VOCABX('HONEY   ',2)
       HORN=VOCABX('HORN    ',2)
       JEWELS=VOCABX('JEWELS  ',2)
       KEYS=VOCABX('KEYS    ',2)
       KNIFE=VOCABX('KNIFE   ',2)
       LAMP=VOCABX('LAMP    ',2)
       LYRE=VOCABX('LYRE    ',2)
       MAGZIN=VOCABX('MAGAZI  ',2)
       MESSAG=VOCABX('MESSAG  ',2)
       MIRROR=VOCABX('MIRROR  ',2)
       MUSHRM=VOCABX('MUSHRO  ',2)
       NUGGET=VOCABX('NUGGET  ',2)
       OIL=VOCABX('OIL     ',2)
C       OIL2=OIL+1
       OYSTER=VOCABX('OYSTER  ',2)
       PLAQUE=VOCABX('PLAQUE  ',2)
       PEARL=VOCABX('PEARL   ',2)
       PHONE=VOCABX('PHONE   ',2)
       PILLOW=VOCABX('PILLOW  ',2)
       PLANT=VOCABX('PLANT   ',2)
       PLANT2=PLANT+1
       POLE=VOCABX('POLE    ',2)
       POSTER=VOCABX('POSTER  ',2)
       PYRAM=VOCABX('PYRAMI  ',2)
       RADIUM=VOCABX('RADIUM  ',2)
       RING=VOCABX('RING    ',2)
       ROCKS=VOCABX('ROCKS   ',2)
       ROD=VOCABX('ROD    ',2)
       ROD2=ROD+1
       RUG=VOCABX('RUG     ',2)
       SAFE=VOCABX('SAFE    ',2)
       SHIELD=VOCABX('TUBE    ',2)
       SHOES=VOCABX('SHOES   ',2)
       SKEY=VOCABX('KEY     ',2)
       SLUGS=VOCABX('SLUGS   ',2)
       SNAKE=VOCABX('SNAKE   ',2)
       SPICES=VOCABX('SPICES  ',2)
      SPIDER=VOCABX('SPIDER  ',2)
       STEPS=VOCABX('STEPS   ',2)
       STICKS=VOCABX('STICKS  ',2)
       SWORD=VOCABX('SWORD   ',2)
       TABLET=VOCABX('TABLET  ',2)
       TDOOR=DOOR+1
       TDOOR2=TDOOR+1
       PDOOR=TDOOR2+1
       TRIDNT=VOCABX('TRIDEN  ',2)
       TROLL=VOCABX('TROLL   ',2)
       TROLL2=TROLL+1
       VASE=VOCABX('VASE    ',2)
       VEND=VOCABX('MACHIN  ',2)
       WALL=VOCABX('WALL    ',2)
       WALL2=WALL+1
       WATER=VOCABX('WATER   ',2)
C       WATER2=WATER+1
       WINE=VOCABX('WINE    ',2)
C       WINE2=WINE+1
       WUMPUS=VOCABX('WUMPUS  ',2)

C  THESE ARE MOTION-VERB NUMBERS.

       BACK=VOCABX('BACK    ',1)
       CAVE=VOCABX('CAVE    ',1)
       DPRSSN=VOCABX('DEPRES  ',1)
       ENTRNC=VOCABX('ENTRAN  ',1)
       EXIT=VOCABX('EXIT    ',1)
       NULL=VOCABX('NULL    ',1)

C  AND SOME ACTION VERBS.

       FIND=VOCABX('FIND    ',3)
       GO=VOCABX('GO      ',3)
       HIT=VOCABX('HIT     ',3)
       LOOK=VOCABX('LOOK    ',3)
       YELL=VOCABX('CALL    ',3)
       INVENT=VOCABX('INVENT  ',3)
       LEAVE=VOCABX('LEAVE   ',3)
       LOCK=VOCABX('LOCK    ',3)
       SAY=VOCABX('SAY     ',3)
       SHUT=VOCABX('CLOSE   ',3)
       TAKE=VOCABX('TAKE    ',3)
       THROW=VOCABX('THROW   ',3)
       UNLOCK=VOCABX('UNLOCK  ',3)
       WEAR=VOCABX('WEAR    ',3)
       YANK=VOCABX('YANK    ',3)

C  AND A FEW PREPOSITIONS.  PREFIX 'PREP' TO DISTINGUISH THEM FROM FUNCTIONS & R

       PREPAT=VOCABX('AT      ',5)
       PREPDN=VOCABX('DOWN    ',5)
       PREPFR=VOCABX('FROM    ',5)
       PREPIN=VOCABX('IN      ',5)
       PREPOF=VOCABX('OFF     ',5)
       PREPON=VOCABX('ON      ',5)

C  A POPULAR LOCATION IS:

       Y2=33
C  IF SETUP=2 WE DON'T NEED TO DO THIS.  IT'S ONLY NECESSARY IF WE HAVEN'T DONE
C  IT AT ALL OR IF THE PROGRAM HAS BEEN RUN SINCE THEN.

1200    IF(SETUP.EQ.2)GOTO 1
       IF(SETUP.EQ.-1)GOTO 13050

C  HAVING READ IN THE DATABASE, CERTAIN THINGS ARE NOW CONSTRUCTED.  PROPS ARE
C  SET TO ZERO.  WE FINISH SETTING UP COND BY CHECKING FOR FORCED-MOTION TRAVEL
C  ENTRIES.  THE PLAC AND FIXD ARRAYS ARE USED TO SET UP ATLOC(N) AS THE FIRST
C  OBJECT AT LOCATION N, AND LINK(OBJ) AS THE NEXT OBJECT AT THE SAME LOCATION
C  AS OBJ.  (OBJ>MAXOBJ INDICATES THAT FIXED(OBJ-MAXOBJ)=LOC; LINK(OBJ) IS STILL
C  THE CORRECT LINK TO USE.)  ABB IS ZEROED; IT CONTROLS WHETHER THE ABBREVIATED
C  DESCRIPTION IS PRINTED.  COUNTS MOD 5 UNLESS "LOOK" IS USED.

       DO 1201 I=1,MAXOBJ
       PLACE(I)=0
       PROP(I)=0
       HOLDER(I)=0
       HLINK(I)=0
       LINK(I)=0
1201    LINK(I+MAXOBJ)=0

       DO 1202 I=1,LOCSIZ
       ABB(I)=0
       IF(LTEXT(I).EQ.0.OR.KEY(I).EQ.0)GOTO 1202
       K=KEY(I)
       IF(MOD(IABS(TRAVEL(K)),0001000).EQ.1)LOCCON(I)=2
1202    ATLOC(I)=0

C  SET UP THE ATLOC AND LINK ARRAYS AS DESCRIBED ABOVE.  WE'LL USE THE DROP
C  SUBROUTINE, WHICH PREFACES NEW OBJECTS ON THE LISTS.  SINCE WE WANT THINGS
C  IN THE OTHER ORDER, WE'LL RUN THE LOOP BACKWARDS.  IF THE OBJECT IS IN TWO
C  LOCS, WE DROP IT TWICE.  THIS ALSO SETS UP "PLACE" AND "FIXED" AS COPIES OF
C  "PLAC" AND "FIXD".  ALSO, SINCE TWO-PLACED OBJECTS ARE TYPICALLY BEST
C  DESCRIBED LAST, WE'LL DROP THEM FIRST.

       DO 1206 I=1,MAXOBJ
       K=MAXOBJ+1-I
       IF(FIXD(K).LE.0)GOTO 1206
       CALL DROP(K+MAXOBJ,FIXD(K))
       CALL DROP(K,PLAC(K))
1206    CONTINUE

       DO 1207 I=1,MAXOBJ
       K=MAXOBJ+1-I
       FIXED(K)=FIXD(K)
1207    IF(PLAC(K).NE.0.AND.FIXD(K).LE.0)CALL DROP(K,PLAC(K))

C  MAKE SURE ALL THE RIGHT THINGS GET CLOSED AND LOCKED, ETC., BEFORE
C  WE GET STARTED.

       DO 1220 I=1,MAXOBJ
1220    OBJCON(I)=OBJCND(I)

C  TREASURES, AS NOTED EARLIER, ARE OBJECTS WITH BITSET(14) IN OBJCON.
C  THEIR PROPS ARE INITIALLY -1, AND ARE SET TO 0 THE FIRST TIME THEY ARE
C  DESCRIBED.  TALLY KEEPS TRACK OF HOW MANY ARE NOT YET FOUND, SO WE KNOW
C  WHEN TO CLOSE THE CAVE.  TALLY2 COUNTS HOW MANY CAN NEVER BE FOUND (E.G. IF
C  LOST BIRD OR BRIDGE).

       TALLY=0
       TALLY2=0
       DO 1240 I=1,MAXOBJ
       IF(.NOT.TREASR(I))GOTO 1240
       IF(PTEXT(I).NE.0)PROP(I)=-1
1240    TALLY=TALLY-PROP(I)


C  CLEAR THE HINT STUFF.  HINTLC(I) IS HOW LONG HE'S BEEN AT LOC WITH COND BIT
C  I.  HINTED(I) IS TRUE IFF HINT I HAS BEEN USED.

       DO 1300 I=1,HNTMAX
       HINTED(I)=.FALSE.
1300    HINTLC(I)=0

C  INITIALISE THE DWARVES.  DLOC IS LOC OF DWARVES, HARD-WIRED IN.  ODLOC IS
C  PRIOR LOC OF EACH DWARF, INITIALLY GARBAGE.  DALTLC IS ALTERNATE INITIAL LOC
C  FOR DWARF, IN CASE ONE OF THEM STARTS OUT ON TOP OF THE ADVENTURER.  (NO 2
C  OF THE 5 INITIAL LOCS ARE ADJACENT.)  DSEEN IS TRUE IF DWARF HAS SEEN HIM.
C  DFLAG CONTROLS THE LEVEL OF ACTIVATION OF ALL THIS:
C       0       NO DWARF STUFF YET (WAIT UNTIL REACHES HALL OF MISTS)
C       1       REACHED HALL OF MISTS, BUT HASN'T MET FIRST DWARF
C       2       MET FIRST DWARF, OTHERS START MOVING, NO KNIVES THROWN YET
C       3       A KNIFE HAS BEEN THROWN (FIRST SET ALWAYS MISSES)
C       3+      DWARVES ARE MAD (INCREASES THEIR ACCURACY)
C  SIXTH DWARF IS SPECIAL (THE PIRATE).  HE ALWAYS STARTS AT HIS CHEST'S
C  EVENTUAL LOCATION INSIDE THE MAZE.  THIS LOC IS SAVED IN CHLOC FOR REF.
C  THE DEAD END IN THE OTHER MAZE HAS ITS LOC STORED IN CHLOC2.

       CHLOC=114
       CHLOC2=140
       DO 1700 I=1,DWFMAX
1700    DSEEN(I)=.FALSE.
       DFLAG=0
       DLOC(1)=PLAC(SNAKE)
       DLOC(2)=PLAC(BOOTH)
       DLOC(3)=Y2
       DLOC(4)=44
       DLOC(5)=PLAC(CLAM)
C       DLOC(6)=PLAC(VEND)
       DLOC(DWFMAX)=CHLOC
       DALTLC=PLAC(NUGGET)

C  OTHER RANDOM FLAGS AND COUNTERS, AS FOLLOWS:
C       ABBNUM  HOW OFTEN WE SHOULD PRINT NON-ABBREVIATED DESCRIPTIONS
C       BCROSS  NUMBER OF TIMES COLLAPSING BRIDGE HAS BEEN TRAVERSED.
C       BONUS   USED TO DETERMINE AMOUNT OF BONUS IF HE REACHES CLOSING
C       CHASE   TELLS HOW CLOSE THE WUMPUS IS TO GOBBLING HIM UP
C       CLOCK1  NUMBER OF TURNS FROM FINDING LAST TREASURE TILL CLOSING
C       CLOCK2  NUMBER OF TURNS FROM FIRST WARNING TILL BLINDING FLASH
C       CLOCK3  NUMBER OF TURNS IN REPOSITORY TILL PHONE RINGS.
C               AFTER TICKING TO 0, TICKS 7 TIMES TO WAKE DWARVES.
C       COMBO   CURRENT PROGRESS IN GIVING SAFE'S COMBINATION
C       DETAIL  HOW OFTEN WE'VE SAID "NOT ALLOWED TO GIVE MORE DETAIL"
C       DKILL   NUMBER OF DWARVES KILLED (UNUSED IN SCORING, NEEDED FOR MSG)
C       FOOBAR  CURRENT PROGRESS IN SAYING "FEE FIE FOE FOO".
C       HEALTH  PERCENTAGE OF MAXIMUM (100) FITNESS
C       IWEST   HOW MANY TIMES HE'S SAID "WEST" INSTEAD OF "W"
C       KNFLOC  0 IF NO KNIFE HERE, LOC IF KNIFE HERE, -1 AFTER CAVEAT
C       LIMIT   LIFETIME OF LAMP (NOT SET HERE)
C       MAXDIE  NUMBER OF REINCARNATION MESSAGES AVAILABLE (UP TO 5)
C       NUMDIE  NUMBER OF TIMES KILLED SO FAR
C       TERSE   IF TRUE, NEVER PRINT LONG LOCATION DESCRIPTIONS
C       TURNS   TALLIES HOW MANY COMMANDS HE'S GIVEN (IGNORES YES/NO)
C       WASTE   TELLS HOW LONG HE HAS USED LAMP IN LIGHTED AREA.

C       LOGICALS WERE EXPLAINED EARLIER

       ABBNUM=5
       BCROSS=0
       BONUS=0
       CLOCK1=30
       CLOCK2=50
       CLOCK3=20+RAN(20)
       CHASE=0
       CLOSED=.FALSE.
       CLOSNG=.FALSE.
       COMBO=0
       DETAIL=0
       DKILL=0
       FOOBAR=0
       GAVEUP=.FALSE.
       HEALTH=100
       IWEST=0
       KNFLOC=0
       LMWARN=.FALSE.
       DO 1800 I=0,4
1800    IF(RTEXT(2*I+81).NE.0)MAXDIE=I+1
       NUMDIE=0
       PANIC=.FALSE.
       SAVED=0
       SCORNG=.FALSE.
       TERSE=.FALSE.
       TURNS=0
       WASTE=0

C  SETUP THE LIQUIDS ACCORDING TO CONTAINER PROP VALUES
       LIQTYP(1)=WATER
       LIQTYP(2)=0
       LIQTYP(3)=OIL
       LIQTYP(4)=0
       LIQTYP(5)=WINE

       PROP(POLE)=1
       PROP(SKEY)=1
       PLACE(WATER)=-1
       CALL INSERT(WATER,BOTTLE)
       PLACE(BOOK)=-1
       CALL INSERT(BOOK,SAFE)

C  AND CLEAR OUT ANY LEFTOVER WORD VECTORS...
       CALL CLRLIN
       DO 1810 WDX=1,35
1810    WORDS(WDX)=0
       WDX=0

C  IF SETUP=1, REPORT ON AMOUNT OF ARRAYS ACTUALLY USED, TO PERMIT REDUCTIONS.

       IF(SETUP.NE.1)GOTO 1
       SETUP=2

       JJ=0
       DO 1989 K=1,VKYSIZ
1989    IF(VKEY(K).NE.0)JJ=JJ+1

       DO 1998 K=1,LOCSIZ
       KK=LOCSIZ+1-K
       IF(LTEXT(KK).NE.0)GOTO 1997
1998    CONTINUE

1997    LL=0
       OBJ=0
       DO 1996 K=1,MAXOBJ
       IF(TREASR(K))LL=LL+1
1996    IF(PTEXT(K).NE.0)OBJ=OBJ+1

       DO 1995 K=1,TABNDX
1995    IF(KTAB(K)/1000.EQ.2)VERB=KTAB(K)-2000

       DO 1994 K=1,RTXSIZ
       J=RTXSIZ+1-K
       IF(RTEXT(J).NE.0)GOTO 1993
1994    CONTINUE

1993    DO 1992 K=1,MAGSIZ
       I=MAGSIZ+1-K
       IF(MTEXT(I).NE.0)GOTO 1991
1992    CONTINUE

1991    CALL RATING(SCORE,MXSCOR,0,0,0,0,0)
       K=MAXOBJ
       PRINT 1999,LINUSE,LINSIZ,TRVS,TRVSIZ,TABNDX,TABSIZ,KK,
     1  LOCSIZ,OBJ,K,LL,VERB,VRBSIZ,J,RTXSIZ,CLSSES,CLSMAX,
     2  HNTMAX,HNTSIZ,I,MAGSIZ,PTBS,PTBSIZ,JJ,VERB,
     3  MXSCOR
1999    FORMAT (' TABLE SPACE USED:'/
     1  ' ',I6,' OF ',I6,' WORDS OF MESSAGES'/
     2  ' ',I6,' OF ',I6,' TRAVEL OPTIONS'/
     3  ' ',I6,' OF ',I6,' VOCABULARY WORDS'/
     4  ' ',I6,' OF ',I6,' LOCATIONS'/
     5  ' ',I6,' OF ',I6,' OBJECTS OF WHICH ',I2,' ARE TREASURES.'/
     6  ' ',I6,' OF ',I6,' ACTION VERBS'/
     7  ' ',I6,' OF ',I6,' RTEXT MESSAGES'/
     8  ' ',I6,' OF ',I6,' CLASS MESSAGES'/
     9  ' ',I6,' OF ',I6,' HINTS'/
     1  ' ',I6,' OF ',I6,' MAGIC MESSAGES'/
     2  ' ',I6,' OF ',I6,' VERB/PREP/OBJ OPTIONS'/
     3  ' ',I6,' OF ',I6,' VERBS TAKE PREPOSITIONS'/
     4  /' MAXIMUM SCORE FOR THIS VERSION IS ',I4,' POINTS.'/
     5  )

C  FINALLY, SINCE WE'RE CLEARLY SETTING THINGS UP FOR THE FIRST TIME...

       IF(YESM(33,0,0))CALL XMAP
       CALL POOF
       PAUSE 5
C  START-UP, DWARF STUFF

1       DEMO=START(0)
       CALL MOTD(.FALSE.)
       I=RAN(1)
       CALL RSPEAK(325)
       HINTED(3)=YES(65,1,0)
       NEWLOC=1
       SETUP=3
       LIMIT=280
       IF(HINTED(3))LIMIT=550

C  CAN'T LEAVE CAVE ONCE IT'S CLOSING (EXCEPT BY MAIN OFFICE).

2       IF(.NOT.OUTSID(NEWLOC).OR.NEWLOC.EQ.0.OR..NOT.CLOSNG)GOTO 71
       CALL RSPEAK(130)
       NEWLOC=LOC
       IF(.NOT.PANIC)CLOCK2=15
       PANIC=.TRUE.

C  SEE IF A DWARF HAS SEEN HIM AND HAS COME FROM WHERE HE WANTS TO GO.  IF SO,
C  THE DWARF'S BLOCKING HIS WAY.  IF COMING FROM PLACE FORBIDDEN TO PIRATE
C  (DWARVES ROOTED IN PLACE) LET HIM GET OUT (AND ATTACKED).

71    IF(NEWLOC.EQ.LOC)GOTO 74
      ILOC=LOC
171   IF(FORCED(ILOC))GOTO 74
172   IF(AND(LOCCON(ILOC),000016).NE.0)GOTO 74
      L1=DWFMAX-1
       DO 73 I=1,L1
       IF(ODLOC(I).NE.NEWLOC.OR..NOT.DSEEN(I))GOTO 73
       NEWLOC=LOC
       CALL RSPEAK(2)
       GOTO 74
73      CONTINUE
74      LOC=NEWLOC

C  DWARF STUFF.  SEE EARLIER COMMENTS FOR DESCRIPTION OF VARIABLES.  REMEMBER
C  SIXTH DWARF IS PIRATE AND IS THUS VERY DIFFERENT EXCEPT FOR MOTION RULES.

C  FIRST OFF, DON'T LET THE DWARVES FOLLOW HIM INTO A PIT OR A WALL.  ACTIVATE
C  THE WHOLE MESS THE FIRST TIME HE GETS AS FAR AS THE HALL OF MISTS (LOC 15).
C  IF NEWLOC IS FORBIDDEN TO PIRATE (IN PARTICULAR, IF IT'S BEYOND THE TROLL
C  BRIDGE), BYPASS DWARF STUFF.  THAT WAY PIRATE CAN'T STEAL RETURN TOLL, AND
C  DWARVES CAN'T MEET THE BEAR.  ALSO MEANS DWARVES WON'T FOLLOW HIM INTO DEAD
C  END IN MAZE, BUT C'EST LA VIE.  THEY'LL WAIT FOR HIM OUTSIDE THE DEAD END.

       IF(LOC.EQ.0.OR.FORCED(LOC).OR.AND(LOCCON(NEWLOC),000016).NE.0)
     1  GOTO 2000
       IF(DFLAG.NE.0)GOTO 6000
       IF(INSIDE(LOC))DFLAG=1
       GOTO 2000

C  WHEN WE ENCOUNTER THE FIRST DWARF, WE KILL 0, 1, OR 2 OF THE DWFMAX DWARVES.
C  IF ANY OF THE SURVIVORS IS AT LOC, REPLACE HIM WITH THE ALTERNATE.

6000    IF(DFLAG.NE.1)GOTO 6010
       IF(.NOT.INSIDE(LOC).OR.PCT(95))GOTO 2000
       DFLAG=2
       DO 6001 I=1,2
       J=1+RAN(DWFMAX-1)
C  IF SAVED NOT = -1, HE BYPASSED THE "START" CALL.
6001    IF(PCT(50).AND.SAVED.EQ.-1)DLOC(J)=0
      L1=DWFMAX-1
       DO 6002 I=1,L1
       IF(DLOC(I).EQ.LOC)DLOC(I)=DALTLC
6002    ODLOC(I)=DLOC(I)
       CALL RSPEAK(3)
       CALL DROP(AXE,LOC)
       GOTO 2000

C  THINGS ARE IN FULL SWING.  MOVE EACH DWARF AT RANDOM, EXCEPT IF HE'S SEEN US
C  HE STICKS WITH US.  DWARVES NEVER GO TO LOCS WHICH ARE OUTSIDE OR IN
C  EITHER OF THE TWO PORTAL AREAS.  IF WANDERING AT RANDOM, THEY
C  DON'T BACK UP UNLESS THERE'S NO ALTERNATIVE.  IF THEY DON'T HAVE TO
C  MOVE, THEY ATTACK.  AND, OF COURSE, DEAD DWARVES DON'T DO MUCH OF ANYTHING.

6010    DTOTAL=0
       ATTACK=0
       STICK=0
       DO 6030 I=1,DWFMAX
       IF(DLOC(I).EQ.0)GOTO 6030
       J=1
       KK=KEY(DLOC(I))
       IF(KK.EQ.0)GOTO 6016
6012    NEWLOC=MOD(IABS(TRAVEL(KK))/1000,1000)
       IF(NEWLOC.GT.MAXLOC.OR.NEWLOC.EQ.ODLOC(I)
     1  .OR..NOT.INSIDE(NEWLOC)
     2  .OR.(J.GT.1.AND.NEWLOC.EQ.TK(J-1)).OR.J.GE.20
     3  .OR.NEWLOC.EQ.DLOC(I).OR.FORCED(NEWLOC)
     4  .OR.(I.EQ.DWFMAX.AND.AND(LOCCON(NEWLOC),000016).NE.0)
     5  .OR.IABS(TRAVEL(KK))/1000.EQ.100)GOTO 6014
       TK(J)=NEWLOC
       J=J+1
6014    KK=KK+1
       IF(TRAVEL(KK-1).GE.0)GOTO 6012
6016    TK(J)=ODLOC(I)
       IF(J.GE.2)J=J-1
       J=1+RAN(J)
       ODLOC(I)=DLOC(I)
       DLOC(I)=TK(J)
       DSEEN(I)=(DSEEN(I).AND.INSIDE(LOC))
     1  .OR.(DLOC(I).EQ.LOC.OR.ODLOC(I).EQ.LOC)
       IF(.NOT.DSEEN(I))GOTO 6030
       DLOC(I)=LOC
       IF(I.NE.DWFMAX)GOTO 6027

C  THE PIRATE'S SPOTTED HIM.  HE LEAVES HIM ALONE ONCE WE'VE FOUND CHEST.
C  K COUNTS IF A TREASURE IS HERE.  IF NOT, AND TALLY=TALLY2 PLUS ONE FOR
C  AN UNSEEN CHEST, LET THE PIRATE BE SPOTTED.

       IF(LOC.EQ.CHLOC.OR.PROP(CHEST).GE.0)GOTO 6030
       K=0
       DO 6020 J=1,MAXOBJ
C  PIRATE WON'T TAKE PYRAMID FROM PLOVER ROOM OR DARK ROOM (TOO EASY!).
       IF(.NOT.TREASR(J).OR.(J.EQ.CASK.AND.LIQ(CASK).NE.WINE))GOTO 6020
       IF(J.EQ.PYRAM.AND.(LOC.EQ.PLAC(PYRAM)
     1  .OR.LOC.EQ.PLAC(EMRALD)))GOTO 6020
       IF(TOTING(J).AND.ATHAND(J))GOTO 6022
6020    IF(HERE(J).AND.TREASR(J))K=1
       IF(TALLY.EQ.TALLY2+1.AND.K.EQ.0.AND.PLACE(CHEST).EQ.0
     1  .AND.ATHAND(LAMP).AND.PROP(LAMP).EQ.1)GOTO 6025
       IF(ODLOC(DWFMAX).NE.DLOC(DWFMAX).AND.PCT(30))CALL RSPEAK(127)
       GOTO 6030

6022    CALL RSPEAK(128)
C  DON'T STEAL CHEST BACK FROM TROLL!
       IF(PLACE(MESSAG).EQ.0)CALL MOVE(CHEST,CHLOC)
       CALL MOVE(MESSAG,CHLOC2)
       DO 6023 J=1,MAXOBJ
       IF(.NOT.TREASR(J).OR.(J.EQ.PYRAM.AND.
     1  (LOC.EQ.PLAC(PYRAM).OR.LOC.EQ.PLAC(EMRALD))).OR.
     2  (J.EQ.CASK.AND.LIQ(CASK).NE.WINE).OR.
     3  (ENCLSD(J).AND..NOT.ATHAND(J)))GOTO 6023
       IF(AT(J).AND.FIXED(J).EQ.0)CALL CARRY(J,LOC)
       IF(ENCLSD(J))CALL REMOVE(J)
       IF(.NOT.HOLDNG(J))GOTO 6023
       CALL INSERT(J,CHEST)
       IF(.NOT.WEARNG(J))GOTO 6023
       PROP(J)=0
       CALL BITOFF(J,WEARBT)
6023    CONTINUE
6024    DLOC(DWFMAX)=CHLOC
       ODLOC(DWFMAX)=CHLOC
       DSEEN(DWFMAX)=.FALSE.
       GOTO 6030

6025    CALL RSPEAK(186)
       CALL MOVE(CHEST,CHLOC)
       CALL MOVE(MESSAG,CHLOC2)
       GOTO 6024

C  THIS THREATENING LITTLE DWARF IS IN THE ROOM WITH HIM!

6027    DTOTAL=DTOTAL+1
       IF(ODLOC(I).NE.DLOC(I))GOTO 6030
       ATTACK=ATTACK+1
       IF(KNFLOC.GE.0)KNFLOC=LOC
       IF(RAN(1000).LT.95*(DFLAG-2))STICK=STICK+1
6030    CONTINUE

