C SAVE- SAVE GAME STATE
C
C COPYRIGHT 1980, INFOCOM COMPUTERS AND COMMUNICATIONS, CAMBRIDGE MA. 02142
C ALL RIGHTS RESERVED, COMMERCIAL USAGE STRICTLY PROHIBITED
C WRITTEN BY R. M. SUPNIK
C
C DECLARATIONS
C
       SUBROUTINE SAVEGM
       IMPLICIT INTEGER (A-Z)
C
C PARSER OUTPUT
C
       LOGICAL PRSWON
       COMMON /PRSVEC/ PRSA,PRSI,PRSO,PRSWON,PRSCON
C
C GAME STATE
C
       LOGICAL TELFLG
       COMMON /PLAY/ WINNER,HERE,TELFLG
       COMMON /STATE/ MOVES,DEATHS,RWSCOR,MXSCOR,MXLOAD,
     1       LTSHFT,BLOC,MUNGRM,HS,EGSCOR,EGMXSC
C
C SCREEN OF LIGHT
C
       COMMON /SCREEN/ FROMDR,SCOLRM,SCOLAC
C
C PUZZLE ROOM
C
       COMMON /PUZZLE/ CPDR(16),CPWL(8),CPVEC(64)
C
C MISCELLANEOUS VARIABLES
C
       COMMON /VERS/ VMAJ,VMIN,VEDIT
       COMMON /TIME/ PLTIME,SHOUR,SMIN,SSEC
C
C ROOMS
C
       COMMON /ROOMS/ RLNT,RDESC2,RDESC1(200),REXIT(200),
     1       RACTIO(200),RVAL(200),RFLAG(200)
C
C EXITS
C
       COMMON /EXITS/ XLNT,TRAVEL(900)
C
C OBJECTS
C
       COMMON /OBJCTS/ OLNT,ODESC1(220),ODESC2(220),ODESCO(220),
     1       OACTIO(220),OFLAG1(220),OFLAG2(220),OFVAL(220),
     2       OTVAL(220),OSIZE(220),OCAPAC(220),OROOM(220),
     3       OADV(220),OCAN(220),OREAD(220)
C
C
C CLOCK INTERRUPTS
C
       LOGICAL CFLAG
       COMMON /CEVENT/ CLNT,CTICK(25),CACTIO(25),CFLAG(25)
C
C
C VILLAINS AND DEMONS
C
       LOGICAL THFFLG,SWDACT,THFACT
       COMMON /HACK/ THFPOS,THFFLG,THFACT,SWDACT,SWDSTA
       COMMON /VILL/ VLNT,VILLNS(4),VPROB(4),VOPPS(4),VBEST(4),VMELEE(4)
C
C ADVENTURERS
C
       COMMON /ADVS/ ALNT,AROOM(4),ASCORE(4),AVEHIC(4),
     1       AOBJ(4),AACTIO(4),ASTREN(4),AFLAG(4)
C
C FLAGS
C
       LOGICAL FLAGS(46)
       INTEGER SWITCH(22)
       COMMON /FINDEX/ FLAGS,SWITCH
C
       PRSWON=.FALSE. 
C DISABLE GAME.
       OPEN (UNIT=11,FILE='DSAVE.DAT',ACCESS='SEQUENTIAL',
     1       STATUS='UNKNOWN',FORM='UNFORMATTED',ERR=100)
C
       CALL GTTIME(I) 
C GET TIME.
       WRITE(11) VMAJ,VMIN,VEDIT
       WRITE(11) WINNER,HERE,THFPOS,TELFLG,THFFLG,THFACT,
     1       SWDACT,SWDSTA,CPVEC
       WRITE(11) I,MOVES,DEATHS,RWSCOR,EGSCOR,MXLOAD,
     1       LTSHFT,BLOC,MUNGRM,HS,FROMDR,SCOLRM,SCOLAC
       WRITE(11) ODESC1,ODESC2,OFLAG1,OFLAG2,OFVAL,OTVAL,
     1       OSIZE,OCAPAC,OROOM,OADV,OCAN
       WRITE(11) RVAL,RFLAG
       WRITE(11) AROOM,ASCORE,AVEHIC,ASTREN,AFLAG
       WRITE(11) FLAGS,SWITCH,VPROB,CFLAG,CTICK
C
       CLOSE(UNIT=11)
       CALL RSPEAK(597)
       RETURN
C
100       CALL RSPEAK(598)  
C CANT DO IT.
       RETURN
       END
C RESTORE- RESTORE GAME STATE
C
C DECLARATIONS
C
       SUBROUTINE RSTRGM
       IMPLICIT INTEGER (A-Z)
C
C PARSER OUTPUT
C
       LOGICAL PRSWON
       COMMON /PRSVEC/ PRSA,PRSI,PRSO,PRSWON,PRSCON
C
C GAME STATE
C
       LOGICAL TELFLG
       COMMON /PLAY/ WINNER,HERE,TELFLG
       COMMON /STATE/ MOVES,DEATHS,RWSCOR,MXSCOR,MXLOAD,
     1       LTSHFT,BLOC,MUNGRM,HS,EGSCOR,EGMXSC
C
C SCREEN OF LIGHT
C
       COMMON /SCREEN/ FROMDR,SCOLRM,SCOLAC
C
C PUZZLE ROOM
C
       COMMON /PUZZLE/ CPDR(16),CPWL(8),CPVEC(64)
C
C MISCELLANEOUS VARIABLES
C
       COMMON /VERS/ VMAJ,VMIN,VEDIT
       COMMON /TIME/ PLTIME,SHOUR,SMIN,SSEC
C
C ROOMS
C
       COMMON /ROOMS/ RLNT,RDESC2,RDESC1(200),REXIT(200),
     1       RACTIO(200),RVAL(200),RFLAG(200)
C
C EXITS
C
       COMMON /EXITS/ XLNT,TRAVEL(900)
C
C OBJECTS
C
       COMMON /OBJCTS/ OLNT,ODESC1(220),ODESC2(220),ODESCO(220),
     1       OACTIO(220),OFLAG1(220),OFLAG2(220),OFVAL(220),
     2       OTVAL(220),OSIZE(220),OCAPAC(220),OROOM(220),
     3       OADV(220),OCAN(220),OREAD(220)
C
C
C CLOCK INTERRUPTS
C
       LOGICAL CFLAG
       COMMON /CEVENT/ CLNT,CTICK(25),CACTIO(25),CFLAG(25)
C
C
C VILLAINS AND DEMONS
C
       LOGICAL THFFLG,SWDACT,THFACT
       COMMON /HACK/ THFPOS,THFFLG,THFACT,SWDACT,SWDSTA
       COMMON /VILL/ VLNT,VILLNS(4),VPROB(4),VOPPS(4),VBEST(4),VMELEE(4)
C
C ADVENTURERS
C
       COMMON /ADVS/ ALNT,AROOM(4),ASCORE(4),AVEHIC(4),
     1       AOBJ(4),AACTIO(4),ASTREN(4),AFLAG(4)
C
C FLAGS
C
       LOGICAL FLAGS(46)
       INTEGER SWITCH(22)
       COMMON /FINDEX/ FLAGS,SWITCH
C
       PRSWON=.FALSE.  
C DISABLE GAME.
       OPEN (UNIT=11,FILE='DSAVE.DAT',ACCESS='SEQUENTIAL',
     1       STATUS='OLD',FORM='UNFORMATTED',ERR=100)
C
       READ(11) I,J,K
       IF((I.NE.VMAJ).OR.(J.NE.VMIN)) GO TO 200
C
       READ(11) WINNER,HERE,THFPOS,TELFLG,THFFLG,THFACT,
     1       SWDACT,SWDSTA,CPVEC
       READ(11) PLTIME,MOVES,DEATHS,RWSCOR,EGSCOR,MXLOAD,
     1       LTSHFT,BLOC,MUNGRM,HS,FROMDR,SCOLRM,SCOLAC
       READ(11) ODESC1,ODESC2,OFLAG1,OFLAG2,OFVAL,OTVAL,
     1       OSIZE,OCAPAC,OROOM,OADV,OCAN
       READ(11) RVAL,RFLAG
       READ(11) AROOM,ASCORE,AVEHIC,ASTREN,AFLAG
       READ(11) FLAGS,SWITCH,VPROB,CFLAG,CTICK
C
       CLOSE(UNIT=11)
       CALL RSPEAK(599)
       RETURN
C
100       CALL RSPEAK(598)  
C CANT DO IT.
       RETURN
C
200       CALL RSPEAK(600)  
C OBSOLETE VERSION
       CLOSE (UNIT=1)
       RETURN
       END
C WALK- MOVE IN SPECIFIED DIRECTION
C
C DECLARATIONS
C
       LOGICAL FUNCTION WALK()
       IMPLICIT INTEGER(A-Z)
       LOGICAL FINDXT,QOPEN,LIT,PROB,MOVETO,RMDESC
C
C PARSER OUTPUT
C
       LOGICAL PRSWON
       COMMON /PRSVEC/ PRSA,PRSI,PRSO,PRSWON,PRSCON
C
C GAME STATE
C
       LOGICAL TELFLG
       COMMON /PLAY/ WINNER,HERE,TELFLG
C
C ROOMS
C
       COMMON /ROOMS/ RLNT,RDESC2,RDESC1(200),REXIT(200),
     1       RACTIO(200),RVAL(200),RFLAG(200)
C
       COMMON /RFLAG/ RSEEN,RLIGHT,RLAND,RWATER,RAIR,
     1       RSACRD,RFILL,RMUNG,RBUCK,RHOUSE,RNWALL,REND
C
C EXITS
C
       COMMON /CURXT/ XTYPE,XROOM1,XSTRNG,XACTIO,XOBJ
C
       COMMON /XSRCH/ XMIN,XMAX,XDOWN,XUP,
     1       XNORTH,XSOUTH,XENTER,XEXIT,XEAST,XWEST
C
C OBJECTS
C
       COMMON /OBJCTS/ OLNT,ODESC1(220),ODESC2(220),ODESCO(220),
     1       OACTIO(220),OFLAG1(220),OFLAG2(220),OFVAL(220),
     2       OTVAL(220),OSIZE(220),OCAPAC(220),OROOM(220),
     3       OADV(220),OCAN(220),OREAD(220)
C
       COMMON /OFLAGS/ VISIBT,READBT,TAKEBT,DOORBT,TRANBT,FOODBT,
     1       NDSCBT,DRNKBT,CONTBT,LITEBT,VICTBT,BURNBT,FLAMBT,
     2       TOOLBT,TURNBT,ONBT
       COMMON /OFLAGS/ FINDBT,SLEPBT,SCRDBT,TIEBT,CLMBBT,ACTRBT,
     1       WEAPBT,FITEBT,VILLBT,STAGBT,TRYBT,NOCHBT,OPENBT,
     2       TCHBT,VEHBT,SCHBT
C
       LOGICAL CFLAG
       COMMON /CEVENT/ CLNT,CTICK(25),CACTIO(25),CFLAG(25)
C
       COMMON /CINDEX/ CEVCUR,CEVMNT,CEVLNT,CEVMAT,CEVCND,
     1       CEVBAL,CEVBRN,CEVFUS,CEVLED,CEVSAF,CEVVLG,
     2       CEVGNO,CEVBUC,CEVSPH,CEVEGH,
     3       CEVFOR,CEVSCL,CEVZGI,CEVZGO,CEVSTE,
     5       CEVMRS,CEVPIN,CEVINQ,CEVFOL
 
C
C VILLAINS AND DEMONS
C
       LOGICAL THFFLG,SWDACT,THFACT
       COMMON /HACK/ THFPOS,THFFLG,THFACT,SWDACT,SWDSTA
       COMMON /VILL/ VLNT,VILLNS(4),VPROB(4),VOPPS(4),VBEST(4),VMELEE(4)
C
C ADVENTURERS
C
       COMMON /AINDEX/ PLAYER,AROBOT,AMASTR
C
C FLAGS
C
       LOGICAL FLAGS(46)
       EQUIVALENCE (FLAGS(1),TROLLF)
       LOGICAL TROLLF,CAGESF,BUCKTF,CAROFF,CAROZF,LWTIDF
       LOGICAL DOMEF,GLACRF,ECHOF,RIDDLF,LLDF,CYCLOF
       LOGICAL MAGICF,LITLDF,SAFEF,GNOMEF,GNODRF,MIRRMF
       LOGICAL EGYPTF,ONPOLF,BLABF,BRIEFF,SUPERF,BUOYF
       LOGICAL GRUNLF,GATEF,RAINBF,CAGETF,EMPTHF,DEFLAF
       LOGICAL GLACMF,FROBZF,ENDGMF,BADLKF,THFENF,SINGSF
       LOGICAL MRPSHF,MROPNF,WDOPNF,MR1F,MR2F,INQSTF
       LOGICAL FOLLWF,SPELLF,CPOUTF,CPUSHF
       COMMON /FINDEX/ TROLLF,CAGESF,BUCKTF,CAROFF,CAROZF,LWTIDF,
     1       DOMEF,GLACRF,ECHOF,RIDDLF,LLDF,CYCLOF,
     2       MAGICF,LITLDF,SAFEF,GNOMEF,GNODRF,MIRRMF,
     3       EGYPTF,ONPOLF,BLABF,BRIEFF,SUPERF,BUOYF,
     4       GRUNLF,GATEF,RAINBF,CAGETF,EMPTHF,DEFLAF,
     5       GLACMF,FROBZF,ENDGMF,BADLKF,THFENF,SINGSF,
     6       MRPSHF,MROPNF,WDOPNF,MR1F,MR2F,INQSTF,
     7       FOLLWF,SPELLF,CPOUTF,CPUSHF
       COMMON /FINDEX/ BTIEF,BINFF
       COMMON /FINDEX/ RVMNT,RVCLR,RVCYC,RVSND,RVGUA
       COMMON /FINDEX/ ORRUG,ORCAND,ORMTCH,ORLAMP
       COMMON /FINDEX/ MDIR,MLOC,POLEUF
       COMMON /FINDEX/ QUESNO,NQATT,CORRCT
       COMMON /FINDEX/ LCELL,PNUMB,ACELL,DCELL,CPHERE
C
C FUNCTIONS AND DATA
C
       QOPEN(O)=ZAND(OFLAG2(O),OPENBT).NE.0
C WALK, PAGE 2
C
       WALK=.TRUE. 
C ASSUME WINS.
       IF((WINNER.NE.PLAYER).OR.LIT(HERE).OR.PROB(25,25))
     1       GO TO 500
       IF(.NOT.FINDXT(PRSO,HERE)) GO TO 450 
C INVALID EXIT? GRUE
C 
       GO TO (400,200,100,300),XTYPE   
C DECODE EXIT TYPE.
       CALL BUG(9,XTYPE)
C
100       IF(CXAPPL(XACTIO).NE.0) GO TO 400 
C CEXIT... RETURNED ROOM?
       IF(FLAGS(XOBJ)) GO TO 400   
C NO, FLAG ON?
200       CALL JIGSUP(523)  
C BAD EXIT, GRUE
C 
       RETURN
C
300       IF(CXAPPL(XACTIO).NE.0) GO TO 400 
C DOOR... RETURNED ROOM?
       IF(QOPEN(XOBJ)) GO TO 400   
C NO, DOOR OPEN?
       CALL JIGSUP(523)  
C BAD EXIT, GRUE
C 
       RETURN
C
400       IF(LIT(XROOM1)) GO TO 900   
C VALID ROOM, IS IT LIT?
450       CALL JIGSUP(522)  
C NO, GRUE
C 
       RETURN
C
C ROOM IS LIT, OR WINNER IS NOT PLAYER (NO GRUE).
C
500       IF(FINDXT(PRSO,HERE)) GO TO 550   
C EXIT EXIST?
525       XSTRNG=678 
C ASSUME WALL.
       IF(PRSO.EQ.XUP) XSTRNG=679   
C IF UP, CANT.
       IF(PRSO.EQ.XDOWN) XSTRNG=680   
C IF DOWN, CANT.
       IF(ZAND(RFLAG(HERE),RNWALL).NE.0) XSTRNG=524
       CALL RSPEAK(XSTRNG)
       PRSCON=1 
C STOP CMD STREAM.
       RETURN
C
550       GO TO (900,600,700,800),XTYPE 
C BRANCH ON EXIT TYPE.
       CALL BUG(9,XTYPE)
C
700       IF(CXAPPL(XACTIO).NE.0) GO TO 900 
C CEXIT... RETURNED ROOM?
       IF(FLAGS(XOBJ)) GO TO 900   
C NO, FLAG ON?
600       IF(XSTRNG.EQ.0) GO TO 525   
C IF NO REASON, USE STD.
       CALL RSPEAK(XSTRNG)  
C DENY EXIT.
       PRSCON=1 
C STOP CMD STREAM.
       RETURN
C
800       IF(CXAPPL(XACTIO).NE.0) GO TO 900 
C DOOR... RETURNED ROOM?
       IF(QOPEN(XOBJ)) GO TO 900   
C NO, DOOR OPEN?
       IF(XSTRNG.EQ.0) XSTRNG=525   
C IF NO REASON, USE STD.
       CALL RSPSUB(XSTRNG,ODESC2(XOBJ))
       PRSCON=1 
C STOP CMD STREAM.
       RETURN
C
900       WALK=MOVETO(XROOM1,WINNER)   
C MOVE TO ROOM.
       IF(WALK) WALK=RMDESC(0)  
C DESCRIBE ROOM.
       RETURN
       END
C CXAPPL- CONDITIONAL EXIT PROCESSORS
C
C DECLARATIONS
C
       INTEGER FUNCTION CXAPPL(RI)
       IMPLICIT INTEGER (A-Z)
C
C GAME STATE
C
       LOGICAL TELFLG
       COMMON /PLAY/ WINNER,HERE,TELFLG
C
C PARSER OUTPUT
C
       LOGICAL PRSWON
       COMMON /PRSVEC/ PRSA,PRSI,PRSO,PRSWON,PRSCON
C
C PUZZLE ROOM
C
       COMMON /PUZZLE/ CPDR(16),CPWL(8),CPVEC(64)
C
C ROOMS
C
       COMMON /ROOMS/ RLNT,RDESC2,RDESC1(200),REXIT(200),
     1       RACTIO(200),RVAL(200),RFLAG(200)
C
       COMMON /RINDEX/ WHOUS,LROOM,CELLA
       COMMON /RINDEX/ MTROL,MAZE1
       COMMON /RINDEX/ MGRAT,MAZ15
       COMMON /RINDEX/ FORE1,FORE3,CLEAR,RESER
       COMMON /RINDEX/ STREA,EGYPT,ECHOR
       COMMON /RINDEX/ TSHAF
       COMMON /RINDEX/ BSHAF,MMACH,DOME,MTORC
       COMMON /RINDEX/ CAROU
       COMMON /RINDEX/ RIDDL,LLD2,TEMP1,TEMP2,MAINT
       COMMON /RINDEX/ BLROO,TREAS,RIVR1,RIVR2,RIVR3,MCYCL
       COMMON /RINDEX/ RIVR4,RIVR5,FCHMP,FALLS,MBARR
       COMMON /RINDEX/ MRAIN,POG,VLBOT,VAIR1,VAIR2,VAIR3,VAIR4
       COMMON /RINDEX/ LEDG2,LEDG3,LEDG4,MSAFE,CAGER
       COMMON /RINDEX/ CAGED,TWELL,BWELL,ALICE,ALISM,ALITR
       COMMON /RINDEX/ MTREE,BKENT,BKVW,BKTWI,BKVAU,BKBOX
       COMMON /RINDEX/ CRYPT,TSTRS,MRANT,MREYE
       COMMON /RINDEX/ MRA,MRB,MRC,MRG,MRD,FDOOR
       COMMON /RINDEX/ MRAE,MRCE,MRCW,MRGE,MRGW,MRDW,INMIR
       COMMON /RINDEX/ SCORR,NCORR,PARAP,CELL,PCELL,NCELL
       COMMON /RINDEX/ CPANT,CPOUT,CPUZZ
C
C EXITS
C
       COMMON /EXITS/ XLNT,TRAVEL(900)
C
       COMMON /CURXT/ XTYPE,XROOM1,XSTRNG,XACTIO,XOBJ
C
       COMMON /XPARS/ XRMASK,XDMASK,XFMASK,XFSHFT,XASHFT,
     1       XELNT(4),XNORM,XNO,XCOND,XDOOR,XLFLAG
C
       COMMON /XSRCH/ XMIN,XMAX,XDOWN,XUP,
     1       XNORTH,XSOUTH,XENTER,XEXIT,XEAST,XWEST
C
C OBJECTS
C
       COMMON /OBJCTS/ OLNT,ODESC1(220),ODESC2(220),ODESCO(220),
     1       OACTIO(220),OFLAG1(220),OFLAG2(220),OFVAL(220),
     2       OTVAL(220),OSIZE(220),OCAPAC(220),OROOM(220),
     3       OADV(220),OCAN(220),OREAD(220)
C
       COMMON /OFLAGS/ VISIBT,READBT,TAKEBT,DOORBT,TRANBT,FOODBT,
     1       NDSCBT,DRNKBT,CONTBT,LITEBT,VICTBT,BURNBT,FLAMBT,
     2       TOOLBT,TURNBT,ONBT
       COMMON /OFLAGS/ FINDBT,SLEPBT,SCRDBT,TIEBT,CLMBBT,ACTRBT,
     1       WEAPBT,FITEBT,VILLBT,STAGBT,TRYBT,NOCHBT,OPENBT,
     2       TCHBT,VEHBT,SCHBT
C
       COMMON /OINDEX/ GARLI,FOOD,GUNK,COAL,MACHI,DIAMO,TCASE,BOTTL
       COMMON /OINDEX/ WATER,ROPE,KNIFE,SWORD,LAMP,BLAMP,RUG
       COMMON /OINDEX/       LEAVE,TROLL,AXE
       COMMON /OINDEX/ RKNIF,KEYS,ICE,BAR
       COMMON /OINDEX/ COFFI,TORCH,TBASK,FBASK,IRBOX
       COMMON /OINDEX/ GHOST,TRUNK,BELL,BOOK,CANDL
       COMMON /OINDEX/ MATCH,TUBE,PUTTY,WRENC,SCREW,CYCLO,CHALI
       COMMON /OINDEX/ THIEF,STILL,WINDO,GRATE,DOOR
       COMMON /OINDEX/ HPOLE,LEAK,RBUTT,RAILI
       COMMON /OINDEX/ POT,STATU,IBOAT,DBOAT,PUMP,RBOAT
       COMMON /OINDEX/ STICK,BUOY,SHOVE,BALLO,RECEP,GUANO
       COMMON /OINDEX/ BROPE,HOOK1,HOOK2,SAFE,SSLOT,BRICK,FUSE
       COMMON /OINDEX/ GNOME,BLABE,DBALL,TOMB
       COMMON /OINDEX/ LCASE,CAGE,RCAGE,SPHER,SQBUT
       COMMON /OINDEX/ FLASK,POOL,SAFFR,BUCKE,ECAKE,ORICE,RDICE,BLICE
       COMMON /OINDEX/ ROBOT,FTREE,BILLS,PORTR,SCOL,ZGNOM
       COMMON /OINDEX/ EGG,BEGG,BAUBL,CANAR,BCANA
       COMMON /OINDEX/ YLWAL,RDWAL,PINDR,RBEAM
       COMMON /OINDEX/ ODOOR,QDOOR,CDOOR,NUM1,NUM8
       COMMON /OINDEX/ WARNI,CSLIT,GCARD,STLDR
       COMMON /OINDEX/ HANDS,WALL,LUNGS,SAILO,AVIAT,TEETH
       COMMON /OINDEX/ ITOBJ,EVERY,VALUA,OPLAY,WNORT,GWATE,MASTER
C
       COMMON /AINDEX/ PLAYER,AROBOT,AMASTR
C
C FLAGS
C
       LOGICAL TROLLF,CAGESF,BUCKTF,CAROFF,CAROZF,LWTIDF
       LOGICAL DOMEF,GLACRF,ECHOF,RIDDLF,LLDF,CYCLOF
       LOGICAL MAGICF,LITLDF,SAFEF,GNOMEF,GNODRF,MIRRMF
       LOGICAL EGYPTF,ONPOLF,BLABF,BRIEFF,SUPERF,BUOYF
       LOGICAL GRUNLF,GATEF,RAINBF,CAGETF,EMPTHF,DEFLAF
       LOGICAL GLACMF,FROBZF,ENDGMF,BADLKF,THFENF,SINGSF
       LOGICAL MRPSHF,MROPNF,WDOPNF,MR1F,MR2F,INQSTF
       LOGICAL FOLLWF,SPELLF,CPOUTF,CPUSHF
       COMMON /FINDEX/ TROLLF,CAGESF,BUCKTF,CAROFF,CAROZF,LWTIDF,
     1       DOMEF,GLACRF,ECHOF,RIDDLF,LLDF,CYCLOF,
     2       MAGICF,LITLDF,SAFEF,GNOMEF,GNODRF,MIRRMF,
     3       EGYPTF,ONPOLF,BLABF,BRIEFF,SUPERF,BUOYF,
     4       GRUNLF,GATEF,RAINBF,CAGETF,EMPTHF,DEFLAF,
     5       GLACMF,FROBZF,ENDGMF,BADLKF,THFENF,SINGSF,
     6       MRPSHF,MROPNF,WDOPNF,MR1F,MR2F,INQSTF,
     7       FOLLWF,SPELLF,CPOUTF,CPUSHF
       COMMON /FINDEX/ BTIEF,BINFF
       COMMON /FINDEX/ RVMNT,RVCLR,RVCYC,RVSND,RVGUA
       COMMON /FINDEX/ ORRUG,ORCAND,ORMTCH,ORLAMP
       COMMON /FINDEX/ MDIR,MLOC,POLEUF
       COMMON /FINDEX/ QUESNO,NQATT,CORRCT
       COMMON /FINDEX/ LCELL,PNUMB,ACELL,DCELL,CPHERE
C CXAPPL, PAGE 2
C
       CXAPPL=0 
C NO RETURN.
       IF(RI.EQ.0) RETURN  
C IF NO ACTION, DONE.
       GO TO (1000,2000,3000,4000,5000,6000,7000,
     1       8000,9000,10000,11000,12000,13000,14000),RI
       CALL BUG(5,RI)
C
C C1- COFFIN-CURE
C
1000       EGYPTF=OADV(COFFI).NE.WINNER   
C T IF NO COFFIN.
       RETURN
C
C C2- CAROUSEL EXIT
C C5- CAROUSEL OUT
C
2000       IF(CAROFF) RETURN  
C IF FLIPPED, NOTHING.
2500       CALL RSPEAK(121)  
C SPIN THE COMPASS.
5000       I=XELNT(XCOND)*ZRND(8)  
C CHOOSE RANDOM EXIT.
       XROOM1=ZAND((TRAVEL(REXIT(HERE)+I)),XRMASK)
       CXAPPL=XROOM1 
C RETURN EXIT.
       RETURN
C
C C3- CHIMNEY FUNCTION
C
3000       LITLDF=.FALSE.  
C ASSUME HEAVY LOAD.
       J=0
       DO 3100 I=1,OLNT  
C COUNT OBJECTS.
         IF(OADV(I).EQ.WINNER) J=J+1
3100       CONTINUE
C
       IF(J.GT.2) RETURN  
C CARRYING TOO MUCH?
       XSTRNG=446 
C ASSUME NO LAMP.
       IF(OADV(LAMP).NE.WINNER) RETURN   
C NO LAMP?
       LITLDF=.TRUE. 
C HE CAN DO IT.
       IF(ZAND(OFLAG2(DOOR),OPENBT).EQ.0)
     1       OFLAG2(DOOR)=ZAND(OFLAG2(DOOR),ZNOT(TCHBT))
       RETURN
C
C C4-       FROBOZZ FLAG (MAGNET ROOM, FAKE EXIT)
C C6-       FROBOZZ FLAG (MAGNET ROOM, REAL EXIT)
C
4000       IF(CAROFF) GO TO 2500  
C IF FLIPPED, GO SPIN.
       FROBZF=.FALSE. 
C OTHERWISE, NOT AN EXIT.
       RETURN
C
6000       IF(CAROFF) GO TO 2500  
C IF FLIPPED, GO SPIN.
       FROBZF=.TRUE. 
C OTHERWISE, AN EXIT.
       RETURN
C
C C7-       FROBOZZ FLAG (BANK ALARM)
C
7000       FROBZF=(OROOM(BILLS).NE.0).AND.(OROOM(PORTR).NE.0)
       RETURN
C CXAPPL, PAGE 3
C
C C8-       FROBOZZ FLAG (MRGO)
C
8000       FROBZF=.FALSE. 
C ASSUME CANT MOVE.
       IF(MLOC.NE.XROOM1) GO TO 8100   
C MIRROR IN WAY?
       IF((PRSO.EQ.XNORTH).OR.(PRSO.EQ.XSOUTH)) GO TO 8200
       IF(MOD(MDIR,180).NE.0) GO TO 8300 
C MIRROR MUST BE N-S.
       XROOM1=((XROOM1-MRA)*2)+MRAE   
C CALC EAST ROOM.
       IF(PRSO.GT.XSOUTH) XROOM1=XROOM1+1 
C IF SW/NW, CALC WEST.
8100       CXAPPL=XROOM1
       RETURN
C
8200       XSTRNG=814 
C ASSUME STRUC BLOCKS.
       IF(MOD(MDIR,180).EQ.0) RETURN   
C IF MIRROR N-S, DONE.
8300       LDIR=MDIR 
C SEE WHICH MIRROR.
       IF(PRSO.EQ.XSOUTH) LDIR=180
       XSTRNG=815 
C MIRROR BLOCKS.
       IF(((LDIR.GT.180).AND..NOT.MR1F).OR.
     1  ((LDIR.LT.180).AND..NOT.MR2F)) XSTRNG=816 
C MIRROR BROKEN.
       RETURN
C
C C9-       FROBOZZ FLAG (MIRIN)
C
9000       IF(MRHERE(HERE).NE.1) GO TO 9100 
C MIRROR 1 HERE?
       IF(MR1F) XSTRNG=805  
C SEE IF BROKEN.
       FROBZF=MROPNF 
C ENTER IF OPEN.
       RETURN
C
9100       FROBZF=.FALSE. 
C NOT HERE,
       XSTRNG=817 
C LOSE.
       RETURN
C CXAPPL, PAGE 4
C
C C10-       FROBOZZ FLAG (MIRROR EXIT)
C
10000       FROBZF=.FALSE. 
C ASSUME CANT.
       LDIR=((PRSO-XNORTH)/XNORTH)*45   
C XLATE DIR TO DEGREES.
       IF(.NOT.MROPNF .OR.
     1       ((MOD(MDIR+270,360).NE.LDIR).AND.(PRSO.NE.XEXIT)))
     2       GO TO 10200  
C EXIT VIA MIRROR?
       XROOM1=((MLOC-MRA)*2)+MRAE+1-(MDIR/180) 
C ASSUME E-W EXIT.
       IF(MOD(MDIR,180).EQ.0) GO TO 10100 
C IF N-S, OK.
       XROOM1=MLOC+1 
C ASSUME N EXIT.
       IF(MDIR.GT.180) XROOM1=MLOC-1   
C IF SOUTH.
10100       CXAPPL=XROOM1
       RETURN
C
10200       IF(.NOT.WDOPNF .OR.
     1       ((MOD(MDIR+180,360).NE.LDIR).AND.(PRSO.NE.XEXIT)))
     2       RETURN 
C EXIT VIA OPEN DOOR?
       XROOM1=MLOC+1 
C ASSUME N.
       IF(MDIR.EQ.0) XROOM1=MLOC-1   
C IF S.
       CALL RSPEAK(818)  
C CLOSE DOOR.
       WDOPNF=.FALSE.
       CXAPPL=XROOM1
       RETURN
C
C C11-       MAYBE DOOR.  NORMAL MESSAGE IS THAT DOOR IS CLOSED.
C       BUT IF LCELL.NE.4, DOOR ISNT THERE.
C
11000       IF(LCELL.NE.4) XSTRNG=678   
C SET UP MSG.
       RETURN
C
C C12-       FROBZF (PUZZLE ROOM MAIN ENTRANCE)
C
12000       FROBZF=.TRUE. 
C ALWAYS ENTER.
       CPHERE=10 
C SET SUBSTATE.
       RETURN
C
C C13-       CPOUTF (PUZZLE ROOM SIZE ENTRANCE)
C
13000       CPHERE=52 
C SET SUBSTATE.
       RETURN
C CXAPPL, PAGE 5
C
C C14-       FROBZF (PUZZLE ROOM TRANSITIONS)
C
14000       FROBZF=.FALSE. 
C ASSSUME LOSE.
       IF(PRSO.NE.XUP) GO TO 14100   
C UP?
       IF(CPHERE.NE.10) RETURN  
C AT EXIT?
       XSTRNG=881 
C ASSUME NO LADDER.
       IF(CPVEC(CPHERE+1).NE.-2) RETURN 
C LADDER HERE?
       CALL RSPEAK(882)  
C YOU WIN.
       FROBZF=.TRUE. 
C LET HIM OUT.
       RETURN
C
14100       IF((CPHERE.NE.52).OR.(PRSO.NE.XWEST).OR..NOT.CPOUTF)
     1       GO TO 14200  
C W EXIT AT DOOR?
       FROBZF=.TRUE. 
C YES, LET HIM OUT.
       RETURN
C
14200       DO 14300 I=1,16,2  
C LOCATE EXIT.
         IF(PRSO.EQ.CPDR(I)) GO TO 14400
14300       CONTINUE
       RETURN   
C NO SUCH EXIT.
C
14400       J=CPDR(I+1) 
C GET DIRECTIONAL OFFSET.
       NXT=CPHERE+J 
C GET NEXT STATE.
       K=8   
C GET ORTHOGONAL DIR.
       IF(J.LT.0) K=-8
       IF((((IABS(J).EQ.1).OR.(IABS(J).EQ.8)).OR.
     1   ((CPVEC(CPHERE+K).EQ.0).OR.(CPVEC(NXT-K).EQ.0))).AND.
     2    (CPVEC(NXT).EQ.0)) GO TO 14500 
C CANT DO IT?
       RETURN
C
14500       CALL CPGOTO(NXT)  
C MOVE TO STATE.
       XROOM1=CPUZZ 
C STAY IN ROOM.
       CXAPPL=XROOM1
       RETURN
C
       END
