'     THE WONDERFUL WORLD OF EAMON DELUXE (v2)
'           BY FRANK BLACK
'
'   A COMPUTERIZED FANTASY ROLE-PLAYING SYSTEM
' BASED UPON THE APPLE II VERSION BY DONALD BROWN,
'    JOHN NELSON, TOM ZUCHOWSKI, & FRANK SPORK
'
'              BASE DUNGEON PROGRAM v2.1
'
'  Adventure in Interzone  --  By Frank Black
'
' Converted to Eamon Deluxe: 1997?
' Last Update: 15 NOV 2003

DECLARE SUB Main ()

TYPE DESC
  TEXT AS STRING * 255
END TYPE
DIM SHARED DS AS DESC

TYPE ROOM
  RNAME AS STRING * 79: D1 AS INTEGER: d2 AS INTEGER: D3 AS INTEGER
  D4 AS INTEGER: D5 AS INTEGER: D6 AS INTEGER: D7 AS INTEGER: D8 AS INTEGER
  D9 AS INTEGER: D10 AS INTEGER: Light AS INTEGER
END TYPE
DIM SHARED rm AS ROOM

TYPE ARTIFACT
  aname AS STRING * 35: AD1 AS INTEGER: AD2 AS INTEGER: AD3 AS INTEGER:
  AD4 AS INTEGER: AD5 AS INTEGER: AD6 AS INTEGER: AD7 AS INTEGER:
  AD8 AS INTEGER
END TYPE
DIM SHARED art AS ARTIFACT

TYPE MONSTER
  MNAME AS STRING * 35: MD1 AS INTEGER: MD2 AS INTEGER: MD3 AS INTEGER:
  MD4 AS INTEGER: MD5 AS INTEGER: MD6 AS INTEGER: MD7 AS INTEGER:
  MD8 AS INTEGER: MD9 AS INTEGER: MD10 AS INTEGER: MD11 AS INTEGER
  MD12 AS INTEGER: MD13 AS INTEGER
END TYPE
DIM SHARED mon AS MONSTER

TYPE RECORD
  CNAME AS STRING * 40: Status AS INTEGER: A1 AS INTEGER: a2 AS INTEGER
  a3 AS INTEGER: SP1 AS INTEGER: SP2 AS INTEGER: SP3 AS INTEGER
  SP4 AS INTEGER: WA1 AS INTEGER: WA2 AS INTEGER: WA3 AS INTEGER
  WA4 AS INTEGER: WA5 AS INTEGER: ae AS INTEGER: sex AS INTEGER: gold AS LONG
  bank AS LONG: ac AS INTEGER: WN1 AS STRING * 20: WN2 AS STRING * 20
  WN3 AS STRING * 20: WN4 AS STRING * 20: WCOMPLX1 AS INTEGER
  WCOMPLX2 AS INTEGER: WCOMPLX3 AS INTEGER: WCOMPLX4 AS INTEGER
  WTYPE1 AS INTEGER: WTYPE2 AS INTEGER: WTYPE3 AS INTEGER: WTYPE4 AS INTEGER
  WDICE1 AS INTEGER: WDICE2 AS INTEGER: WDICE3 AS INTEGER: WDICE4 AS INTEGER
  WSIDES1 AS INTEGER: WSIDES2 AS INTEGER: WSIDES3 AS INTEGER
  WSIDES4 AS INTEGER
END TYPE
DIM SHARED z AS RECORD


DIM SHARED nr, naf, ne, nm, aname$, nd, ver, nh, r2, na, r3, ro, q$
DIM SHARED r4, lt, nl, ls, nc, ac, ae, ea, sh, ar, gold, bank, sex, ch
DIM SHARED c, a, m, r, s, F, cz$, a$, s$, s2$, s3$, d2, df, of, die
DIM SHARED hit, up, rl, l, mc, mr%, rec, sl, speed, sy, sy$, suc, tp, v$, wt
DIM SHARED gold1, om$, loan, dly#, CC1#, CC2#, CC3#
'---------------------------------------------------------------------------
'  Set up variable table
'
OPEN "..\SETTINGS.DAT" FOR INPUT AS #1: INPUT #1, dly#, CC1#, CC2#, CC3#: CLOSE

OPEN "NAME.DAT  " FOR INPUT AS #1
INPUT #1, nr, naf, ne, nm, aname$, nd, ver
CLOSE : a = 0: m = a: ro = m

OPEN "HINTDIR.DAT" FOR INPUT AS #1
INPUT #1, nh
DIM SHARED h$(nh), h%(nh, 2)
FOR r = 1 TO nh
   INPUT #1, h$(r), h%(r, 1), h%(r, 2)
NEXT: CLOSE
nr = 54: naf = 50: nm = 49: ne = 112: na = naf + 6: nh = 29
adj1 = 0: adj2 = 0: adj3 = 0: adj4 = 0

READ nc
DIM SHARED a$(na), a%(na, 8), d%(200), m$(nm), m%(nm, 15), r$(nr), r%(nr, 11)
DIM SHARED sa%(4), sp%(4), sm$(3), bv$(5, 2), rb$(5, 1), wp$(5), wa%(5), wp%(na)
DIM SHARED c$(nc), gm$(5), sp$(4), sa$(4), sex$(2), ow$(6), t(10)
DIM SHARED e$(6), of%(5)
'---------------------------------------------------------------------------
'  Input data from files
'
OPEN "ROOMS.DAT" FOR RANDOM AS #1 LEN = 101
OPEN "ARTIFACT.DAT" FOR RANDOM AS #2 LEN = 51
OPEN "MONSTERS.DAT" FOR RANDOM AS #3 LEN = 61
OPEN "NEW-MEAT" FOR RANDOM AS #4 LEN = 200
FOR c = 1 TO nc
   READ c$(c)
NEXT
'
'   Rooms
'
FOR r = 1 TO nr
   GET #1, r, rm
   r$(r) = RTRIM$(rm.RNAME)
   r%(r, 1) = rm.D1: r%(r, 2) = rm.d2: r%(r, 3) = rm.D3: r%(r, 4) = rm.D4
   r%(r, 5) = rm.D5: r%(r, 6) = rm.D6: r%(r, 7) = rm.D7: r%(r, 8) = rm.D8
   r%(r, 9) = rm.D9: r%(r, 10) = rm.D10: r%(r, 11) = rm.Light
NEXT
'
'   Artifacts
'
FOR a = 1 TO naf
   GET #2, a, art
   a$(a) = RTRIM$(art.aname): a%(a, 1) = art.AD1: a%(a, 2) = art.AD2
   a%(a, 3) = art.AD3: a%(a, 4) = art.AD4: a%(a, 5) = art.AD5
   a%(a, 6) = art.AD6: a%(a, 7) = art.AD7: a%(a, 8) = art.AD8
NEXT
'
'   Monsters
'
FOR m = 1 TO nm
   GET #3, m, mon
   m$(m) = RTRIM$(mon.MNAME): m%(m, 1) = mon.MD1: m%(m, 2) = mon.MD2
   m%(m, 3) = mon.MD3: m%(m, 4) = mon.MD4: m%(m, 5) = mon.MD5
   m%(m, 6) = mon.MD6: m%(m, 7) = mon.MD7: m%(m, 8) = mon.MD8
   m%(m, 9) = mon.MD9: m%(m, 10) = mon.MD10: m%(m, 11) = mon.MD11
   m%(m, 12) = m%(m, 3): m%(m, 14) = mon.MD12: m%(m, 15) = mon.MD13
NEXT
'
'   PLAYER
'
a = 1
GET #4, a, z
m$(0) = RTRIM$(z.CNAME): stat = z.Status: m%(0, 1) = z.A1: m%(0, 2) = z.a2
ch = z.a3: sp%(1) = z.SP1: sp%(2) = z.SP2: sp%(3) = z.SP3: sp%(4) = z.SP4
wa%(1) = z.WA1: wa%(2) = z.WA2: wa%(3) = z.WA3: wa%(4) = z.WA4: wa%(5) = z.WA5
ae = z.ae: sex = z.sex: gold = z.gold: bank = z.bank: ac = z.ac
a = naf + 1: m = a + 1: k = a + 2: w = a + 3
a$(a) = RTRIM$(z.WN1): a$(m) = RTRIM$(z.WN2): a$(k) = RTRIM$(z.WN3)
a$(w) = RTRIM$(z.WN4): a%(a, 5) = z.WCOMPLX1: a%(m, 5) = z.WCOMPLX2
a%(k, 5) = z.WCOMPLX3: a%(w, 5) = z.WCOMPLX4: a%(a, 6) = z.WTYPE1
a%(m, 6) = z.WTYPE2: a%(k, 6) = z.WTYPE3: a%(w, 6) = z.WTYPE4
a%(a, 7) = z.WDICE1: a%(m, 7) = z.WDICE2: a%(k, 7) = z.WDICE3
a%(w, 7) = z.WDICE4: a%(a, 8) = z.WSIDES1: a%(m, 8) = z.WSIDES2
a%(k, 8) = z.WSIDES3: a%(w, 8) = z.WSIDES4
CLOSE
FOR a = 1 TO 4
   sa%(a) = sp%(a)
NEXT
'
na = naf
FOR a = 1 TO 4
   a$ = UCASE$(LEFT$(a$(naf + a), 4))
   IF a$ <> "NONE" AND a$ <> "" THEN na = na + 1
NEXT
'
' If no weapons, get rid of Customs Official
'
IF na = naf THEN
  m%(6, 5) = 0: a%(30, 4) = 1: d%(2) = 1
END IF

FOR a = naf + 1 TO na
   a%(a, 2) = 2 + ABS((a%(a, 7) * a%(a, 8) > 25))
   a%(a, 3) = 2: wt = wt + 2: : a%(a, 4) = -1
NEXT
m%(0, 7) = ac / 2 + ABS((sh > 0)): m%(0, 11) = 3
m%(0, 8) = -1: IF na > naf THEN m%(0, 8) = naf + 1
IF ae < ac * ac THEN ea = ae - ac * ac
'
'   Make players armor artifacts
'
FOR a = 1 TO 4
   READ wp$(a)
NEXT
a = INT(ac / 2)
IF a > 4 THEN a = 4
IF a THEN
  na = na + 1: a$(na) = wp$(a) + " armor": a%(na, 2) = 11: a%(na, 3) = a * 7
  a%(na, 4) = -999: wt = wt + a%(na, 3): ar = na
  a%(na, 5) = ac - ABS(ac / 2 <> INT(ac / 2))
END IF
a = ABS((INT(ac / 2) <> ac / 2))
IF a THEN
  na = na + 1: sh = na: a$(na) = "shield": a%(na, 2) = 11: a%(na, 3) = 10
  a%(na, 4) = -999: wt = wt + 10: a%(na, 5) = 1
END IF
'
'   Check for duplicate Art. names
'
CheckDup:
r = 0
FOR a = 1 TO na
   a$(a) = LTRIM$(RTRIM$(a$(a)))
   FOR m = a + 1 TO na
      IF LCASE$(a$(m)) = LCASE$(a$(a)) THEN
        a$(m) = a$(m) + "#": r = 1
      END IF
   NEXT
NEXT
IF r = 1 THEN GOTO CheckDup
'
'    Set starting variable values
'
ro = 1: r2 = 1: r3 = 1: q$ = CHR$(34)
IF m%(0, 8) <> -1 THEN w2 = a%(m%(0, 8), 5)
FOR a = 0 TO 5
   FOR a2 = 0 TO 2
      READ bv$(a, a2)
   NEXT
NEXT
FOR a = 0 TO 5
   FOR a2 = 0 TO 1
      READ rb$(a, a2)
   NEXT
NEXT
FOR a = 1 TO 3: READ sm$(a): NEXT
FOR a = 1 TO 5: READ wp$(a): NEXT
sex$(0) = "Male": sex$(1) = "Female"

IF nd = 6 THEN
  FOR c = 7 TO 10: c$(c) = "": NEXT
END IF
FOR a = naf + 1 TO na
   a%(a, 0) = 1: ow$(a - naf) = a$(a)
NEXT
OPEN "ROOMS.DSC" FOR RANDOM AS #10 LEN = 255
OPEN "ARTIFACT.DSC" FOR RANDOM AS #11 LEN = 255
OPEN "MONSTERS.DSC" FOR RANDOM AS #12 LEN = 255
OPEN "EFFECT.DSC" FOR RANDOM AS #13 LEN = 255

'
' Set up Interzone vars
'
FOR a = 1 TO 8: READ d%(10 + a): d%(20 + a) = 37 + a: NEXT
om$ = m$(0): a%(42, 0) = 1
'
' Monster death text
'
m%(26, 15) = 20: m%(2, 15) = 15: m%(4, 15) = 16: m%(17, 15) = 18
m%(22, 15) = 19: m%(6, 15) = 17
'
'  Error messages for computer (artifact #12)
'
FOR a = 1 TO 6: READ a$: e$(a) = "?" + a$ + " ERROR": NEXT
'
' A.J.'s random comments, d%(40-50)
'
FOR a = 1 TO 11: READ d%(39 + a): NEXT
d%(37) = 1: IF sex = 1 THEN d%(41) = 48

'
' Add non-offensive monsters
'
OPEN "OFFEND.DAT" FOR INPUT AS #2
FOR a = 1 TO 5: INPUT #2, of%(a): NEXT
CLOSE #2
IF of%(1) = 1 THEN
  m%(44, 5) = m%(8, 5): m%(46, 5) = m%(27, 5): m%(48, 5) = m%(30, 5)
  m%(8, 5) = 0: m%(27, 5) = 0: m%(30, 5) = 0
END IF
IF of%(2) = 1 THEN m%(45, 5) = m%(18, 5): m%(18, 5) = 0
IF of%(3) = 1 THEN m%(47, 5) = m%(28, 5): m%(28, 5) = 0

' Don't have to drink
IF of%(5) = 1 THEN d%(31) = 1

' Thug pointer
d%(8) = 41: IF of%(4) = 1 THEN d%(8) = 49

'Monsters who won't follow player
m%(6, 14) = 1: m%(17, 14) = 1: m%(19, 14) = 1: m%(37, 14) = 1
m%(42, 14) = 1: m%(43, 14) = 1: m%(22, 14) = 1: m%(39, 14) = 1
FOR a = 31 TO 35: m%(a, 14) = 1: NEXT

' Ranomize the RND seed
'
CLS : LOCATE 12
PRINT "Welcome to the Eamon Deluxe fantasy gaming system! (MAINPGM v2.1)"
PRINT : PRINT "Hit any key to begin."
a$ = INKEY$
DO
  a = RND
LOOP UNTIL INKEY$ <> ""
CLS : LOCATE 24: r2 = 1

CALL Main

DATA 43,north,south,east,west,up,down,ne,nw,se,sw,flee,board,close,drink,drop
DATA eat,examine,get,light,open,put,read,ready,remove,use,wear,attack,blast
DATA free,give,heal,request,smile,inventory,look,say,speed,power,status,hints
DATA save,restore,quit

'
DATA leather,chain,plate,magic
'
DATA lunges,tears,claws,swings,chops,swings,shoots,shoots,shoots
DATA swings,swings,swings,stabs,lunges,jabs,swings,chops,stabs
'
DATA Missed,Dodged,Parried,Missed,Missed,Dodged,Parried,Missed,Parried,Missed
DATA Dodged,Missed
'
DATA growl,look,smile
'
DATA axe,missile weapon,club,spear,sword
'
' Rooms with signs to read
'
DATA 1,7,9,15,24,25,28,29
'
' Computer error messages
'
DATA SYNTAX,INCORRECT GRAMMER,KEY TOUCHED WRONG,RANDOM ANNOYING
DATA WRONG COMPUTER BRAND,DOES NOT COMPUTE
'
' Pointers to effect # of A.J.'s random comments
'
DATA 2,3,4,5,49,50,51,52,53,54,55

SUB Main
'     THE WONDERFUL WORLD OF EAMON DELUXE
'           BY FRANK BLACK
'
'   A COMPUTERIZED FANTASY ROLE-PLAYING SYSTEM
' BASED UPON THE APPLE II VERSION BY DONALD BROWN,
'    JOHN NELSON, TOM ZUCHOWSKI, & FRANK BLACK
'
'              BASE DUNGEON PROGRAM v2.1
'
'  Adventure in Interzone
'     By Frank Black
'
COLOR 3
IF sa%(2) < 50 OR sa%(4) < 50 THEN
  PRINT "Sorry, but you need to have at least a 50% Heal and Power spell abilities to"
  PRINT "adventure here successfully.": PRINT
  PRINT "Your ratings are"; RTRIM$(STR$(sa%(2))); "% Heal and";
  PRINT RTRIM$(STR$(sa%(4))); "% Power."
  PRINT : GOSUB Lp6: GOTO ExitRtn
END IF
IF gold < 900 THEN
  a$ = "Sorry, " + m$(0) + ", but you'll need at least 900 gold pieces to "
  a$ = a$ + "solve this game.": GOSUB Lp10
  PRINT "You have"; gold; "on hand and"; bank; "in your bank account.": PRINT
  IF gold + bank >= 900 THEN
    PRINT "Withdraw difference from bank?"; : GOSUB AtFr1
    IF s$ = "y" THEN
      bank = bank + gold: bank = bank - 900: gold = 900: GOTO Move2
    END IF
  END IF
  loan = 900 - gold: IF loan < 1 THEN loan = 900
  PRINT "The 6th National Savings & Loan of Interzone will loan you";
  PRINT loan; "gold pieces to be"
  PRINT "repaid when the adventure is over at 0% interest.": PRINT
  PRINT "Do you accept the loan?"; : GOSUB AtFr1
  IF s$ = "n" THEN
    PRINT "Go get some more gold and come back.": GOSUB Lp6: GOTO ExitRtn
  END IF
  gold = gold + loan
END IF
CLS : LOCATE 24: l = 0: GOTO Move2
'---------------------------------------------------------------------------
' Main Loop
'
Main0:
  GOSUB Lp4
Main:
  IF die = 1 THEN GOTO EndGame
  COLOR 12
  GOSUB Lp1: IF ls = 0 THEN GOTO Main2A
  a%(ls, 5) = a%(ls, 5) - 1: m = a%(ls, 5)
  IF m = 0 THEN
    COLOR 2: PRINT "Your "; a$(ls); " has gone out!": COLOR 12
    ls = 0: lt = nl: GOTO Main0
  END IF
Main2A:
  IF speed > 0 THEN
    speed = speed - 1
    IF speed = 0 THEN
      m%(0, 2) = m%(0, 2) / 2
      PRINT "Your speed spell has just expired!": GOSUB Lp4
    END IF
  END IF
Main2B:
  FOR a = 1 TO 4
     IF sa%(a) < sp%(a) THEN sa%(a) = sa%(a) * 1.1
     IF sa%(a) > sp%(a) THEN sa%(a) = sp%(a)
  NEXT
Main3A:
  IF lt = 0 THEN r = 85: GOSUB Effect: GOTO Com0
'
' Give room name and desc
'
Main3B:
  a$ = r$(ro): IF ro = 53 AND d%(1) < 2 THEN a$ = "Progrlm Control Room."
  PRINT a$: GOSUB Lp4
  IF r%(ro, 0) = 0 THEN
    r%(ro, 0) = 1: r = ro: GOSUB DiskRead
  END IF
'
' List monsters in room
'
Main4A:
  m2 = 1
  FOR m = 1 TO nm
     IF m%(m, 5) = ro THEN
       IF m%(m, 0) = 0 THEN
         IF m2 = 0 THEN GOSUB Lp1
         m%(m, 0) = 1: r = m + 800: GOSUB DiskRead: m2 = 1
         IF m%(m, 3) = 1 THEN
           PRINT m$(m); " is here.": GOSUB Lp4: GOTO Main4B
         END IF
         IF m%(m, 3) > 1 THEN
           PRINT LTRIM$(STR$(m%(m, 3))); " "; m$(m); "s are here."
           GOSUB Lp4: : GOTO Main4B
         END IF
       END IF
       m2 = 0
       IF m%(m, 3) = 1 THEN
         PRINT m$(m); " is here.": GOSUB Lp2
       END IF
       IF m%(m, 3) > 1 THEN
         PRINT LTRIM$(STR$(m%(m, 3))); " "; m$(m); "s are here.": GOSUB Lp2
       END IF
     END IF
Main4B:
  NEXT
'
' List artifacts in room
'
Main5A:
  F = 0
  FOR a = 1 TO na
     IF a%(a, 4) <> ro THEN GOTO Main5B
     F = F + 1
     IF a > naf THEN
       IF m2 = 0 AND F = 0 THEN GOSUB Lp1
       PRINT "Your "; a$(a); " is here.": GOSUB Lp2: m2 = 0: GOTO Main5B
     END IF
     IF a%(a, 0) = 0 THEN
       IF m2 = 0 THEN GOSUB Lp1
       a%(a, 0) = 1: r = a + 400: GOSUB DiskRead: m2 = 1
       PRINT "You see "; a$(a); ".": GOSUB Lp2
       IF a%(a, 2) = 4 AND a%(a, 6) = 1 THEN GOSUB Inv4
       GOSUB Lp1: GOTO Main5B
     END IF
     PRINT "You see "; a$(a); ".": GOSUB Lp2: m2 = 0
     IF a%(a, 2) = 4 AND a%(a, 6) = 1 THEN GOSUB Inv4
Main5B:
  NEXT
  COLOR 2: IF m2 = 0 THEN GOSUB Lp1
'
'  Waitress
'
  IF ro = 44 AND d%(4) > 0 THEN
    IF d%(4) = 1 THEN r = 67: GOSUB Effect
    IF d%(4) = 2 OR d%(4) = 3 THEN PRINT "The waitress is crying...": GOSUB Lp4
    IF d%(4) = 4 THEN
      r = 68: GOSUB Effect: m%(35, 5) = 6: GOSUB EC
      d%(4) = 0: GOTO Main
    END IF
    d%(4) = d%(4) + 1
  END IF
'
  IF ro = 52 AND d%(5) = 2 THEN d%(5) = 0: r = 32: GOSUB Effect
'
' Customs Official
'
  IF d%(2) = 0 THEN
    d%(2) = 1: PRINT "Surrender your weapons?"; : GOSUB AtFr1
    IF s$ <> "y" THEN
      PRINT q$; "Then I'll Just have to kill you!"; q$: GOSUB Lp4
      m%(6, 11) = 1: GOSUB EnemyCheck: GOTO Com1
    END IF
    d%(2) = 2: r = 92: GOSUB Effect: m%(6, 11) = 2: m%(6, 5) = 44
    FOR a = naf + 1 TO na
       IF a <> ar AND a <> sh THEN a%(a, 4) = -7
    NEXT
    m%(0, 8) = -1
  END IF
'
' Drunks harrass A.J.
'
  IF d%(3) > 0 AND m%(2, 5) = ro AND m%(39, 5) = ro THEN
    IF d%(3) < 4 THEN PRINT "One Drunk says, ";
    r = 75 + d%(3): GOSUB Effect
    IF d%(3) = 5 THEN
      d%(3) = 0: m%(2, 5) = 2: m%(39, 5) = 2: m%(39, 11) = 1
      m%(2, 13) = 10: GOSUB EC: GOTO Main
    END IF
    d%(3) = d%(3) + 1
  END IF
'
' Clem Snide busts you for letting A.J. die
'
  IF d%(9) > 0 THEN
    d%(9) = d%(9) + 1
    IF d%(9) = 6 THEN
      m%(5, 5) = ro: GOSUB EC: r = 82: GOSUB Effect: GOTO Main
    END IF
    IF d%(9) = 9 THEN
      d%(9) = 0: die = 1: r = 81: GOTO Lp20
    END IF
  END IF
'
' Assault of the thugs
'
  IF d%(10) > 0 THEN
    IF d%(10) = 80 THEN
      m%(d%(8), 5) = ro: GOSUB EC: m%(d%(8), 0) = 1
      r = 800 + d%(8): GOSUB DiskRead
    END IF
    IF d%(10) = 82 THEN
      die = 1: x = 72: IF d%(8) = 49 THEN x = 99
      IF m%(4, 11) <> 3 OR m%(4, 5) <> ro THEN r = x: GOTO Lp20
      IF a%(32, 4) <> -5 THEN r = 73: GOSUB Effect: r = x: GOTO Lp20
      IF a%(34, 4) <> -5 THEN r = 74: GOSUB Effect: r = x: GOTO Lp20
      die = 0: m%(d%(8), 5) = 0: GOSUB EC: r = 75: GOSUB Effect
      d%(10) = 0: d%(4) = 1: GOSUB Lp6: GOTO Main
    END IF
    d%(10) = d%(10) + 1
  END IF
'
' Program Control room
'
  IF ro = 53 THEN
    IF d%(1) = 1 THEN
      d%(1) = 2: r = 93: GOSUB Effect: r = 94: GOSUB Effect: GOTO Main
    END IF
    IF d%(1) = 4 THEN
      r = 64: GOSUB Effect
      IF m%(2, 5) = ro THEN r = 58: GOSUB Effect
      r = 91: GOSUB Effect: r2 = r4: GOTO Move2
    END IF
  END IF
'
  IF ro = 28 AND d%(30) = 1 THEN
    d%(30) = 0: m%(23, 14) = 1: gold = gold + 300: a%(20, 4) = 30
    m%(23, 14) = 1: r = 14: GOSUB Effect
  END IF
'
'  A.J.'s set comments
'
  IF m%(2, 5) = ro THEN
    r = 0: IF d%(7) = 1 THEN d%(7) = 0: r = 62
    IF ro = 3 AND d%(34) = 0 THEN d%(34) = 1: r = 47
    IF ro = 12 AND d%(51) = 0 AND t(1) = 0 THEN d%(51) = 1: r = 48
    IF ro = 24 AND d%(35) = 0 THEN d%(35) = 1: r = 48
    IF ro = 44 AND d%(33) = 0 THEN d%(33) = 1: r = 46
    IF ro = 46 AND d%(39) = 0 THEN d%(39) = 1: r = 105
    IF r > 0 THEN GOSUB Effect
  END IF
'
'  A.J.'s random comments
'
  IF m%(2, 5) = ro AND d%(37) > 0 AND t(1) = 0 THEN
    IF ro <> 3 AND ro <> 44 AND ro <> 24 AND ro <> 46 AND ro <> 52 THEN
      IF d%(37) = 10 THEN
        d%(37) = 1: r = d%(40 + d%(38)): GOSUB Effect: d%(38) = d%(38) + 1
        IF d%(38) = 11 THEN d%(37) = -1
      END IF
      d%(37) = d%(37) + 1
    END IF
  END IF
'
  IF m%(2, 5) = ro AND m%(2, 13) > 2 AND sa%(2) > 20 THEN
    IF d%(36) = 0 THEN d%(36) = 1: r = 84: GOSUB Effect
  END IF
  IF a%(20, 4) = ro AND d%(20) = 1 THEN
    PRINT "You are on your horse.": GOSUB Lp4
  END IF
'---------------------------------------------------------------------------
' Get command
Com0:
  IF lt = 0 THEN
    d%(6) = d%(6) + 1
    IF d%(6) > 3 THEN r = 86: GOSUB Effect: die = 1: GOTO EndGame
  END IF
Com1:
  COLOR 12
  LINE INPUT "Your command?->"; a$: a$ = RTRIM$(LTRIM$(LCASE$(a$)))
  l = 0: GOSUB Lp1
  IF a$ = "" THEN
    a$ = cz$: LOCATE CSRLIN - 2, 16: PRINT a$: PRINT
  END IF
'---------------------------------------------------------------------------
' Parse command
'
  v$ = "": s$ = "": s2$ = "": s3$ = ""
  IF a$ = "" THEN GOTO Err0
  cz$ = a$
  FOR a = 2 TO LEN(a$)
     IF MID$(a$, a, 1) = " " THEN
       v$ = LTRIM$(RTRIM$(LEFT$(a$, a - 1)))
       s$ = LTRIM$(RTRIM$(MID$(a$, a + 1))): a = LEN(a$)
     END IF
  NEXT a
  IF v$ = "" THEN v$ = a$: GOTO Com2
  s3$ = s$
'
  FOR a = 1 TO LEN(s$)
     IF MID$(s$, a, 1) = " " THEN
       s2$ = LTRIM$(RTRIM$(MID$(s$, a + 1)))
       s$ = LTRIM$(RTRIM$(LEFT$(s$, a - 1))): a = LEN(s$)
     END IF
  NEXT
  IF s2$ = "" THEN GOTO Com2
'
  zz$ = LEFT$(s2$, 3)
  IF zz$ = "to " OR zz$ = "on " OR zz$ = "in " THEN
    s2$ = LTRIM$(RTRIM$(MID$(s2$, 4))): GOTO Com2
  END IF
  zz$ = LEFT$(s2$, 5)
  IF zz$ = "from " OR zz$ = "with " THEN
    s2$ = LTRIM$(RTRIM$(MID$(s2$, 6)))
  END IF
Com2:
'
  a = LEN(v$): c = 0
  FOR k = 1 TO nc
     IF v$ = LEFT$(c$(k), a) OR v$ = RIGHT$(c$(k), a) THEN
       c = k: k = nc
     END IF
  NEXT k
  IF c = 0 THEN GOTO Err0
  COLOR 3
  IF c <> 21 AND c <> 24 AND c <> 30 AND c <> 32 THEN s$ = s3$
Com3:
ON c GOTO Move, Move, Move, Move, Move, Move, Move, Move, Move, Move, Flee, Board
ON c - 12 GOTO ItemClose, Drink, Drop, Drink, Examine, ITEMGET, Light, ItemOpen
ON c - 20 GOTO ItemPut, ItemRead, Ready, Remove, Use, Wear
ON c - 26 GOTO Attack, Blast, Free, Give, Heal, Request, Smile
ON c - 33 GOTO Inventory, Look, Say, speed, Power, Status, Hints
ON c - 40 GOTO GameSave, GameRestore, Quit
'---------------------------------------------------------------------------
'  Pick foes
'
Pfoe:
  IF die = 1 THEN GOTO EndGame
  IF t(1) < 0 THEN t(1) = 0
  IF t(1) = 0 THEN GOTO Pfoe3
  GOSUB Lp1: m = 0: m9 = 1
Pfoe0:
  m = m + 1
  IF m%(m, 5) <> ro THEN GOTO Pfoe2A
  IF m%(m, 11) = 2 THEN GOTO Pfoe2A
'
'  Will monster flee?
'
  GOSUB RollDice
  IF m%(m, 13) > 0 THEN rl = rl + 10
  IF m%(m, 13) <= 0 AND m%(m, 12) > m%(m, 3) THEN rl = rl + 10
  IF m%(m, 13) + 4 >= m%(m, 1) THEN rl = rl + 10
  IF rl > m%(m, 4) THEN mr% = 1
  IF mr% = 0 OR m%(m, 4) > 99 THEN GOTO SkipFlee
'
  mr% = INT(RND * m%(m, 3)) + 1
  IF m%(m, 3) > 1 THEN PRINT LTRIM$(RTRIM$(STR$(mr%))); " ";
  PRINT m$(m);
  PRINT MID$("s flee! flees!", ABS(mr% = 1) * 7 + 1, 7): GOSUB Lp4
  IF nx = 0 THEN
    PRINT "But can't find an exit!": GOSUB Lp4: GOTO Pfoe2A
  END IF
  IF mr% = m%(m, 3) THEN
    GOSUB Flee1: m%(m, 5) = r2
    GOSUB EC: GOTO Pfoe2A
  END IF
  m%(m, 3) = m%(m, 3) - mr%: GOSUB EC
'
'  Find an enemy to attack
'
SkipFlee:
  mc = 0: XMC = 1: IF m%(m, 3) > 1 THEN XMC = m%(m, 3)
  of = m: df = 0: IF XMC > 8 THEN XMC = 8
Pfoe0A:
  mc = mc + 1: df = 0
  IF mc > XMC THEN GOTO Pfoe2A
  IF m%(m, 11) = 3 THEN GOTO Pfoe1
'
' Unfriendly monsters find an enemy to attack
'
  IF t(3) = m%(0, 1) THEN GOTO Pfoe2
  FOR m2 = 1 TO nm
     IF m%(m2, 5) = ro AND m%(m2, 11) = 3 AND RND < .45 THEN
       df = m2: m2 = nm
     END IF
  NEXT m2: GOTO Pfoe2
'
' Friendly monsters pick an enemy
'
Pfoe1:
  FOR m2 = 1 TO nm
     IF m%(m2, 5) = ro AND m%(m2, 11) = 1 THEN
       df = m2
       IF df = nm OR RND(1) < .45 THEN m2 = nm
     END IF
  NEXT m2
  IF df = 0 THEN GOTO Pfoe2A
'
'  Send em' off to war
'
Pfoe2:
  GOSUB Battle
  IF die = 1 THEN GOTO EndGame
  IF t(1) > 0 THEN GOTO Pfoe0A
Pfoe2A:
  IF m < nm THEN GOTO Pfoe0
'
'  Every-round events
'
Pfoe3:
  m9 = 0
  FOR of = 1 TO nm
     IF m%(of, 5) = ro AND m%(of, 8) < 0 THEN GOSUB GetWep
  NEXT of
'
' Add your own special stuff here
'
  IF ro = 53 THEN d%(1) = d%(1) + 1
  GOTO Main
'---------------------------------------------------------------------------
' ****  Move commands ****
'
Move:
  IF m%(d%(8), 5) = ro THEN
    PRINT "The thugs won't let you!": GOTO Main0
  END IF
  IF ro = 3 AND m%(39, 5) = ro AND m%(2, 5) = ro THEN
    PRINT "The drunk"; MID$("s", 2 + (m%(39, 3) > 1), 1); " won't let you!": GOTO Main0
  END IF
  r2 = r%(ro, c)
  IF t(1) > 0 AND (nl > 0 OR lt > 0) THEN
    PRINT "You can't do that with unfriendlies about!": GOTO Main0
  END IF
MoveCheck:
  IF r2 > 1000 THEN GOTO Move1
  IF r2 > 0 AND r2 <= nr THEN GOTO Move2
  IF r2 = -999 THEN
    PRINT "You ride off into the sunset."
    DI = 0: GOTO EndGame
  END IF
  r = ABS(r2)
  IF r = 5 THEN r = 56: GOSUB Effect: df = 0: d2 = 2: GOSUB Damage1: GOTO Pfoe
  IF r = 6 AND d%(31) = 0 AND m%(4, 5) = ro THEN r = 103: GOTO Lp20
  IF r = 6 THEN
    IF m%(2, 5) = 52 THEN r = 98: GOSUB Effect: GOTO Main
    GOSUB Effect: IF gold > 6 THEN gold = gold - INT(gold / 6)
    r2 = 7: GOTO Move2
  END IF
  IF r = 7 OR r = 9 THEN GOTO Lp20
  IF r = 8 THEN GOSUB Effect: r2 = 11: GOTO Move2
  IF r = 15 THEN
    IF m%(22, 5) = ro AND d%(52) = 0 THEN PRINT m$(22); " stops you!": GOTO Lp12
    FOR a = naf + 1 TO na: a$(a) = ow$(a - naf): NEXT
    m$(0) = om$: gold = INT(gold): GOSUB Power1: r = 66: GOSUB Effect
    a%(9, 4) = a%(8, 4): a%(15, 4) = a%(11, 4): a%(8, 4) = 0: a%(11, 4) = 0
    GOSUB Lp6: r2 = 32: GOTO Move2
  END IF
  IF r = 31 THEN
    IF a%(20, 4) <> ro THEN die = 1: r = 65: GOTO Lp20
    IF d%(20) = 0 THEN PRINT "You'll need to BOARD your horse!": GOTO Main0
    r2 = 31: GOTO Move2
  END IF
  PRINT "You can't go that way!": GOTO Main0
'
' Doors/Gates
'
Move1:
  a = r2 - 1000
  IF a%(a, 6) = 0 AND a%(a, 7) = 0 AND a%(a, 8) = 0 THEN
    r2 = a%(a, 5): GOTO MoveCheck
  END IF
  IF a%(a, 8) = 1 AND a%(a, 0) = 0 THEN
    PRINT "You can't go that way!": GOTO Main0
  END IF
  PRINT "WHAMM!  You run straight into the door.": GOTO Main0
'
' Go to another room
'
Move2:
  r3 = ro: ro = r2: IF ro <> r3 THEN r4 = r3
  IF ls > 0 AND ls <= na THEN
    IF a%(ls, 4) <> -1 THEN ls = 0
  END IF
  IF r2 = 3 AND m%(39, 14) = 1 THEN
    m%(39, 14) = 0: d%(10) = 1: IF m%(2, 5) = r3 AND m%(39, 5) = r2 THEN d%(3) = 1
  END IF
  IF r2 = 52 AND m%(2, 5) = r3 AND r3 <> r2 THEN d%(5) = 2
  IF r2 = 41 AND r3 = 43 AND m%(2, 5) = 52 AND a%(43, 7) <> 1 THEN
    r = 31: GOSUB Effect: m%(2, 5) = r2
  END IF
  GOSUB EnemyCheck: IF a%(20, 4) = r3 AND d%(20) = 1 THEN a%(20, 4) = ro
  IF ro = 31 THEN d%(20) = 0
  nl = r%(ro, 11): lt = ABS(nl OR ls): nx = 0
  FOR a = 1 TO nd
     nx = nx + ABS(r%(ro, a) > 0 AND r%(ro, a) <= nr AND r%(ro, a) <> ro)
  NEXT
  d%(36) = 0: GOTO Main
'---------------------------------------------------------------------------
' **** Flee command ****
'
Flee:
  IF m%(d%(8), 5) = ro OR (ro = 3 AND m%(39, 5) = ro) THEN GOTO Move
  IF t(1) = 0 THEN
    PRINT "Whatever from?": GOTO Main0
  END IF
  IF nx = 0 THEN
    PRINT "You're trapped!": GOTO Main0
  END IF
  IF ro = 1 AND m%(6, 5) = ro AND m%(6, 11) = 1 THEN
    PRINT m$(6); " firmly blocks your path!": GOTO Lp12
  END IF
  IF s$ <> "" THEN GOTO Flee2
Flee0:
  GOSUB Flee1: GOTO Move2
Flee1:
  r2 = r%(ro, nd * RND + 1)
  IF r2 < 1 OR r2 > nr OR r2 = ro THEN GOTO Flee1
  RETURN
Flee2:
  r2 = 0
  FOR a = 1 TO nd
     IF LEFT$(c$(a), LEN(s$)) = s$ THEN r2 = r%(ro, a)
  NEXT
  IF r2 = 0 THEN GOTO Flee0
  GOTO MoveCheck
'===========================================================================
' **** Board command
'
Board:
  GOSUB CheckSub: GOSUB Asearch0: IF F = 0 THEN GOTO Err3
  IF a <> 20 AND a <> 46 THEN s$ = "that": GOTO Err3
  IF a = 20 THEN
    IF d%(20) = 1 THEN PRINT "You have already mounted!": GOTO Main0
    d%(20) = 1: PRINT "You mount the horse.": GOTO Lp12
  END IF
  COLOR 2: F = 0: k = 0: PRINT "You board the rocket...": PRINT
  a = 12: GOSUB RCode: a = 9: GOSUB RCode: a = 76: GOSUB RCode
  IF F <> 3 THEN
    SOUND 200, 3: PRINT "INVALID CODE!": COLOR 3: l = 99: GOTO Lp12
  END IF
  SOUND 900, 2: PRINT "VALID CODE, COORDINATES ARE SET!": PRINT
  PRINT "Prepare to travel to...": PRINT "  Planet Eamon.": COLOR 3: PRINT
  GOSUB Lp6
  FOR m = 1 TO nm
     IF m%(m, 5) = ro AND m <> 2 THEN
       m%(m, 5) = 24
       IF m%(m, 11) > 1 THEN PRINT m$(m); " bids you farewell!": GOSUB Lp2
       IF m%(m, 11) = 1 THEN PRINT m$(m); " curses at you!": GOSUB Lp2
     END IF
  NEXT
  FOR a = 700 TO 100 STEP -8: SOUND a, 1: NEXT
  GOSUB Lp1: r = 12: GOSUB Effect: r2 = 27: l = 99: GOTO Move2
RCode:
  k = k + 1: PRINT : PRINT "INPUT CODE #"; LTRIM$(STR$(k));
  LINE INPUT ":"; a$: IF VAL(a$) = a THEN F = F + 1
  PRINT : RETURN
'---------------------------------------------------------------------------
' **** Close command ****
'
ItemClose:
  GOSUB CheckSub: GOSUB Asearch0: IF F = 0 THEN GOTO Err1
  x = 0: IF a%(a, 2) = 8 THEN x = 1
  IF a%(a, 2) <> 4 AND x = 0 THEN s$ = "it": GOTO Err3
  IF a%(a, 6 + x) = 0 + x THEN
    PRINT "The "; a$(a); " is already closed.": GOTO Main0
  END IF
  IF a = 43 AND m%(2, 5) = 52 THEN
    COLOR 2: PRINT "SLAMM!!": GOSUB Lp4: r = 33: GOSUB Effect: COLOR 3
  END IF
  PRINT "The "; a$(a); " is now closed.": a%(a, 6 + x) = 0 + x: GOTO Lp12
'---------------------------------------------------------------------------
' **** Drink & Eat commands ****
'
Drink:
  GOSUB CheckSub: GOSUB Asearch0: IF F = 0 THEN GOTO Err3
  IF a <> 42 THEN s$ = "that": GOTO Err3
'
'  Drink in tavern
'
Drink2:
  IF a%(a, 5) = 0 THEN PRINT "It's empty!": GOTO Lp12
  a%(a, 5) = a%(a, 5) - 1
  IF a%(a, 5) = 1 THEN PRINT "Mmm!  That hit the spot!": GOTO Lp12
  PRINT "You slurp up every last drop!": GOSUB Lp4
  a$(a) = "empty mug": IF a%(a, 6) = 5 THEN GOTO Pfoe
  a%(a, 7) = a%(a, 7) + a%(a, 6)
  IF a%(a, 7) < 5 THEN PRINT "You're catching a slight buzz.": GOTO Lp12
  IF a%(a, 7) < 8 THEN
    PRINT "Your head is spinning and your mouth is numb.": GOTO Lp12
  END IF
'
'   Get Drunk
'
  r = 59: GOSUB Effect: gold1 = gold: gold = 0: m%(0, 13) = m%(0, 1) - 5
  m%(0, 8) = -1: a%(42, 4) = 0: m%(0, 7) = 0: wt = a%(8, 4)
  d%(31) = 1: IF gold1 > 0 THEN a%(48, 4) = -3
'
' 10% chance Atari store room, 10% chance Curio store room,
' 30% chance pawn shop, 50% chance random monster has it
' Doctor Benway always gets the shield & I.D. tag
'
  FOR a = 1 TO na
     IF a%(a, 4) = -1 OR a%(a, 4) = -999 THEN
       GOSUB RollDice
       IF rl < 51 THEN a%(a, 4) = 51: a%(a, 0) = 5: a%(47, 4) = -3
       IF rl < 21 THEN a%(a, 4) = 38
       IF rl < 11 THEN a%(a, 4) = 52
       k = INT(RND * 5) + 1 + ABS(k = 2)
       IF rl > 50 THEN a%(a, 4) = -k - 1
       IF a = 30 THEN a%(a, 4) = -1001
     END IF
  NEXT
'
  IF sh > 1 AND sh <= na THEN a%(sh, 4) = -1001
  IF ar > 1 AND ar <= na THEN a%(ar, 4) = 46
  sh = 0: ar = 0: a%(8, 4) = -1
  IF a%(36, 4) <> 546 THEN a%(36, 4) = 46
  IF m%(2, 5) <> 14 THEN
    m%(2, 5) = 45: d%(7) = 1: a%(2, 4) = -3
  END IF
  PRINT "...groan...arrghhh...where am I?": GOSUB Lp4
  PRINT "Anybody get the number of that bus?": GOSUB Lp4
  d2 = 0: df = 0: GOSUB Mstatus: r2 = 46: ro = r2: GOTO Move2
'---------------------------------------------------------------------------
'  **** Drop command ****
'
Drop:
  IF lt = 0 THEN GOTO Main
  GOSUB CheckSub: IF s$ = "all" THEN GOTO Drop1
  GOSUB Asearch
  IF F = 0 THEN
      ha = -999: wh = ha: em = ha: GOSUB Asearch2: IF F = 0 THEN GOTO Err1
      GOTO Give
  END IF
  GOSUB Drop2: GOTO Pfoe
Drop1:
  FOR a = 1 TO na
     IF a%(a, 4) = -1 THEN GOSUB Drop2
  NEXT a
  wt = 0: m%(0, 8) = -1: GOSUB Lp4: GOTO Pfoe
Drop2:
  IF a = m%(0, 8) THEN m%(0, 8) = -1
  wt = wt - a%(a, 3): a%(a, 4) = ro
  PRINT UCASE$(LEFT$(a$(a), 1)); MID$(a$(a), 2); " dropped.": GOSUB Lp2
  IF a = ls THEN
    ls = 0: lt = nl: GOSUB Lp1
    PRINT "The "; a$(a); " goes out.": GOTO Lp4
  END IF
  RETURN
'---------------------------------------------------------------------------
'  **** Examine command ****
'
Examine:
  IF lt = 0 THEN GOTO Main
  GOSUB CheckSub: IF LEFT$(s$, 4) = "room" THEN s$ = "": GOTO Look
  GOSUB Asearch0: IF F = 0 THEN GOTO Examine1
'
' Examine artifact
'
  IF a = 37 AND a%(37, 5) = 0 THEN
    a%(37, 5) = 1: r = 28: GOSUB Effect: a%(32, 4) = ro: a%(33, 4) = ro
    a%(38, 4) = ro: GOTO Pfoe
  END IF
  IF a%(a, 4) = em THEN a%(a, 4) = ro
  IF a%(a, 2) = 8 THEN a%(a, 8) = 0
  IF a > naf OR (a = 42 AND a%(a, 5) = 0) THEN
    PRINT "This is your "; a$(a); ".": GOTO Lp12
  END IF
  IF a = 42 THEN PRINT "It is nice and cold.": GOTO Lp12
  IF a%(a, 2) = 12 THEN GOSUB ItemGet3: GOTO Main
  r = a + 400: GOSUB DiskRead: a%(a, 0) = 1
  IF a = 35 AND a%(36, 0) = 0 THEN
    COLOR 2: PRINT "You found something underneath it!": COLOR 3
    GOSUB Lp4: a%(36, 4) = ro
  END IF
  IF a%(a, 2) = 6 OR a%(a, 2) = 9 THEN
    PRINT "There "; MID$("are is ", ABS(a%(a, 6) = 1) * 4 + 1, 4);
    PRINT LTRIM$(RTRIM$(STR$(a%(a, 6)))); " ";
    PRINT MID$("swallowbite", ABS(a%(a, 2) = 9) * 7 + 1, 7);
    PRINT MID$("s", ABS(a%(a, 6) = 1) * 1 + 1, 1);
    PRINT " left.": GOSUB Lp4
  END IF
  GOTO Pfoe
'
' Examine monster
'
Examine1:
  GOSUB Msearch
  IF F = 0 THEN
    ha = -999: wh = ha: em = ha: GOSUB Asearch2
    IF F = 0 THEN
      PRINT "You see nothing special.": GOTO Lp12
    END IF
    PRINT "This is your "; a$(a); ".": GOTO Lp12
  END IF
  r = m + 800: GOSUB DiskRead: df = m: d2 = 0
  IF m%(m, 3) > 1 AND m%(m, 13) = 0 THEN
    a$ = "They are ": GOSUB Ms1: GOTO Pfoe
  END IF
  GOSUB Mstatus: GOTO Pfoe
'---------------------------------------------------------------------------
'  **** Get command ****
'
ITEMGET:
  IF lt = 0 THEN GOTO Main
  GOSUB CheckSub: IF s$ = "all" THEN GOTO ItemGet2
  ha = ro: GOSUB Asearch2
  IF F = 0 THEN
    GOSUB Msearch: IF F = 0 THEN GOTO Err3
    PRINT m$(m); " says:": GOSUB Lp4
    PRINT q$; "Hey!  Get your stinking hands off of me!"; q$: GOTO Lp12
  END IF
  IF db > 0 AND a >= db AND a <= naf THEN
    PRINT "Dead bodies are best if left alone.": GOTO Main0
  END IF
  IF a%(a, 0) = 5 AND m%(37, 5) = ro THEN
    IF d%(32) = 0 THEN r = 61: GOTO Lp20
    PRINT q$; "You owe me 50 gold pieces!"; q$: GOTO Lp12
  END IF
  IF (a = 32 OR a = 33 OR a = 38) AND a%(37, 6) = 0 THEN
    r = 30: GOTO Lp20
  END IF
  IF a < 25 AND a > 21 AND m%(26, 5) = ro AND m%(26, 11) > 1 THEN
    r = 88: GOSUB Effect: m%(26, 11) = 1: GOSUB EC: GOTO Pfoe
  END IF
  IF a = 42 AND m%(32, 5) = ro THEN
    PRINT "It's property of the bar.  Take anyway?"; : GOSUB AtFr1
    IF s$ <> "y" THEN GOTO Main
    m%(31, 11) = 1: m%(32, 11) = 1: m%(33, 11) = 1: GOSUB EC
    r = 90: GOTO Lp20
  END IF
  GOSUB ItemGet3: GOSUB Lp4: GOTO Pfoe
'
' Get all possible items in room
'
ItemGet2:
  FOR a = 1 TO na
     IF a%(a, 4) = ro THEN
       IF db > 0 AND a >= db AND a <= naf THEN GOTO ItemGet2A
       IF (a < 25 AND a > 21 AND m%(26, 5) = ro) OR a = 42 THEN GOTO ItemGet2A
       IF m%(37, 5) = ro THEN
         IF a%(a, 0) = 5 THEN GOTO ItemGet2A
         IF (a = 32 OR a = 33 OR a = 38) AND a%(37, 6) = 0 THEN GOTO ItemGet2A
       END IF
       IF a%(a, 3) > 900 THEN
         PRINT UCASE$(LEFT$(a$(a), 1)); MID$(a$(a), 2); ": ";
       END IF
       IF a%(a, 3) <> -999 THEN GOSUB ItemGet3
     END IF
ItemGet2A:
  NEXT a: GOTO Pfoe
ItemGet3:
  IF a%(a, 2) = 12 THEN
    PRINT UCASE$(LEFT$(a$(a), 1)); MID$(a$(a), 2); " is alive!": GOSUB Lp4
    IF a%(a, 6) > 0 THEN
      FOR x = 1 TO a%(a, 7)
         r = a%(a, 6) + 1199 + x: GOSUB DiskRead
     NEXT
     END IF
     a%(a, 4) = 0: m%(a%(a, 5), 5) = ro: r3 = ro: GOTO EnemyCheck
  END IF
  IF a%(a, 3) > 900 THEN
    PRINT "Don't be absurd.": GOTO Lp2
  END IF
  IF a%(a, 3) = -999 THEN
    PRINT "You can't get that.": GOTO Lp2
  END IF
  PRINT UCASE$(LEFT$(a$(a), 1)); MID$(a$(a), 2); " ";
  IF wt + a%(a, 3) > 10 * m%(0, 1) THEN
    PRINT "is too heavy.": GOTO Lp2
  END IF
  IF a%(a, 2) = 10 THEN
    PRINT "must be freed.": GOTO Lp2
  END IF
  PRINT "taken.": a%(a, 4) = -1: wt = wt + a%(a, 3)
  IF m%(0, 8) < 1 THEN
    IF a%(a, 2) = 2 OR a%(a, 2) = 3 THEN
      m%(0, 8) = a: GOSUB Lp2: PRINT a$(a); " readied."
    END IF
  END IF
  GOTO Lp2
'---------------------------------------------------------------------------
' **** Light command ****
'
Light:
  GOSUB CheckSub: GOSUB Asearch0: IF F = 0 THEN GOTO Err1
  s$ = "the ": IF a > naf THEN s$ = "your "
  IF a <> 36 THEN s$ = s$ + a$(a): GOTO Err3
  IF a = ls THEN PRINT "You turn it off.": ls = 0: lt = nl: GOTO Lp12
  IF a%(a, 5) = 0 THEN
    PRINT "The batteries are dead!": GOTO Lp12
  END IF
  lt = 1: d%(6) = 0: ls = a: PRINT "You turn on the "; a$(a); ".": GOTO Lp12
'---------------------------------------------------------------------------
' **** Open command ****
'
ItemOpen:
  IF lt = 0 THEN GOTO Main
  GOSUB CheckSub: GOSUB Asearch0: IF F = 0 THEN GOTO Err1
  IF a = 23 THEN r = 100: GOTO Lp20
  m = a%(a, 2): IF m = 8 THEN GOTO DoorOpen
  IF m = 12 THEN GOSUB ItemGet3: GOTO Pfoe
  IF m <> 4 AND m <> 6 AND m <> 7 AND m <> 9 THEN
    s$ = a$(a): GOTO Err3
  END IF
  IF a%(a, 4) = em THEN a%(a, 4) = ro
  k = a%(a, 5): r = a%(a, 7): IF m = 4 THEN r = a%(a, 6)
  IF r = 1 THEN PRINT "It's already open.": GOTO Lp12
'
  IF m = 6 OR m = 7 OR m = 9 THEN
    a%(a, 7) = 1: a$ = "You've opened the " + a$(a) + ".": GOTO Lp9
  END IF
'
  IF k > 0 AND k <= naf THEN
    IF a%(k, 4) <> -1 AND a%(k, 4) <> ro THEN
      PRINT "It's locked.": GOTO Lp12
    END IF
  END IF
  IF a%(a, 6) > 1 THEN
    PRINT "It's locked.": GOTO Lp12
  END IF
  a%(a, 5) = 0: a%(a, 6) = 1
  PRINT UCASE$(LEFT$(a$(a), 1)); MID$(a$(a), 2); " opened.": GOSUB Lp2
  GOSUB Inv4: GOTO Pfoe
'
DoorOpen:
  a%(a, 4) = ro: k = a%(a, 6)
  IF a%(a, 7) = 0 THEN PRINT "It's already open.": GOTO Lp12
'
  IF k > 0 AND k <= naf THEN
    IF a%(k, 4) <> -1 AND a%(k, 4) <> ro THEN
      PRINT "It's locked.": GOTO Lp12
    END IF
    a$ = "You open it with the " + a$(k) + ".": GOSUB Lp10: GOTO DoorOpen1
  END IF
'
  IF a%(a, 7) > 1 THEN
    PRINT "You'll have to force it open.": GOTO Lp12
  END IF
  IF k = -1 THEN PRINT "It won't open.": GOTO Lp12
  a$ = "You've opened the " + a$(a) + ".": GOSUB Lp10
  IF a = 43 AND m%(2, 5) = 52 THEN
    m%(2, 5) = ro: r = 34: GOSUB Effect: GOSUB EC
  END IF
DoorOpen1:
  a%(a, 6) = 0: a%(a, 7) = 0: GOTO Pfoe
'---------------------------------------------------------------------------
' **** Put command ****
'
ItemPut:
  IF lt = 0 THEN GOTO Main
  GOSUB CheckSub: GOSUB Asearch0: IF F = 0 THEN GOTO Err1
  a$ = "Put it in what": GOSUB CheckSub2: s$ = s2$
  GOSUB ItemTake: IF a%(a, 4) <> -1 THEN GOTO Main
  m = a: GOSUB Asearch0: s$ = "anything in that": IF F = 0 THEN GOTO Err1
  IF a = 32 AND m = 34 THEN PRINT "It's already loaded.": GOTO Lp12
  IF a = m OR a%(a, 2) <> 4 THEN GOTO Err3
  IF a%(a, 6) = 0 THEN GOTO Err2
  IF a%(a, 8) < 1 THEN
    PRINT "You don't need to.": GOTO Lp12
  END IF
  IF a%(a, 7) >= a%(a, 8) THEN
    PRINT "It's full.": GOTO Lp12
  END IF
  IF a%(m, 3) > a%(a, 3) THEN
    PRINT "It won't fit.": GOTO Lp12
  END IF
  F = 0
  FOR k = 1 TO na
     IF a%(k, 4) = 1000 + a THEN F = F + a%(k, 3)
  NEXT
  IF F + a%(m, 3) > a%(a, 3) THEN
    PRINT "It's full.": GOTO Lp12
  END IF
  wt = wt - ABS(a%(m, 4) = -1) * a%(m, 3)
  IF m = m%(0, 8) THEN m%(0, 8) = -1
  a%(m, 4) = a + 1000: a%(a, 7) = a%(a, 7) + 1
  IF m = ls THEN
    ls = 0: lt = nl: GOSUB Lp1
    PRINT "(The "; a$(m); " goes out.)": GOSUB Lp4
  END IF
  PRINT "Done.": GOTO Lp12
'---------------------------------------------------------------------------
' **** Read command ****
'
ItemRead:
  r = 0: a$ = "sign": sl = LEN(s$): IF lt = 0 THEN GOTO Main
  IF s$ = LEFT$(a$, sl) OR s$ = RIGHT$(a$, sl) THEN
    FOR a = 1 TO 8
       IF ro = d%(10 + a) THEN r = d%(20 + a)
    NEXT
    IF r = 0 AND ro <> 3 THEN PRINT "I can't see any signs here.": GOTO Pfoe
    IF r > 0 THEN GOSUB ItemRead2: GOTO Pfoe
    PRINT : GOSUB Lp4: LOCATE CSRLIN - 2: COLOR 0, 2
    PRINT "  Today's Special  "; : COLOR 2, 0: PRINT
    PRINT " Beer..........2gp": PRINT " Ale...........3gp"
    PRINT " Death's Grip..4gp": PRINT " Root Beer.....5gp"
    COLOR 3, 0: l = l + 4: GOSUB Lp1: GOTO Pfoe
  END IF
  GOSUB CheckSub: GOSUB Asearch0: IF F = 0 THEN s$ = "that": GOTO Err3
  IF a = 25 THEN PRINT "It hurts your brain.": GOTO Lp12
  IF a%(a, 2) <> 7 THEN r = 37: GOTO Lp20
  IF a%(a, 7) = 0 THEN GOTO Err2
  COLOR 2
  FOR x = 1 TO a%(a, 6)
     r = a%(a, 5) + 1199 + x: GOSUB DiskRead
  NEXT: COLOR 3: GOTO Pfoe
ItemRead2:
  GET #13, r, DS: a$ = RTRIM$(DS.TEXT)
  IF ro = 9 THEN
    PRINT "A crossed-out message reads:": GOSUB Lp4: PRINT : GOSUB Lp4
    LOCATE CSRLIN - 2: COLOR 0, 2
    PRINT " To go east, go east! ": COLOR 3, 0: PRINT
  END IF
  PRINT "The sign says:": GOSUB Lp4
  PRINT : GOSUB Lp4: GOSUB Lp1: LOCATE CSRLIN - 3
  COLOR 0, 6: PRINT SPC(LEN(a$) + 4); : PRINT : PRINT "  "; a$; "  "
  PRINT SPC(LEN(a$) + 4); : COLOR 3, 0: PRINT : GOTO Lp1
'---------------------------------------------------------------------------
' **** Ready command ****
'
Ready:
  GOSUB CheckSub: GOSUB Asearch0: IF F = 0 THEN GOTO Err1
  IF a%(a, 2) <> 2 AND a%(a, 2) <> 3 THEN
    PRINT "That isn't a weapon!": GOSUB Lp2: GOTO Main
  END IF
  GOSUB ItemTake: IF a%(a, 4) <> -1 THEN GOTO Main
  m%(0, 8) = a: w2 = a%(a, 6)
  PRINT UCASE$(LEFT$(a$(a), 1)); MID$(a$(a), 2); " readied.": GOSUB Lp2
  GOTO Pfoe
'---------------------------------------------------------------------------
' **** Remove command ****
'
'    Remove armor
'
Remove:
  GOSUB CheckSub: ha = -999: wh = ha: em = ha: GOSUB Asearch2
  IF F = 0 THEN GOTO Remove1
  IF a = sh THEN
    m%(0, 7) = m%(0, 7) - 1: sh = 0
  END IF
  IF a = ar THEN
    m%(0, 7) = m%(0, 7) - a%(a, 5) / 2: ar = 0
  END IF
  a%(a, 4) = -1
  PRINT UCASE$(LEFT$(a$(a), 1)); MID$(a$(a), 2); " removed."
  GOTO Pfoe
'
' Remove items from a container
'
Remove1:
  IF lt = 0 THEN GOTO Main
  a$ = "From what": GOSUB CheckSub2: a$ = s$: s$ = s2$
  GOSUB Asearch0: IF F = 0 THEN GOTO Err1
  m = a: s$ = a$: wh = a + 1000: ha = wh: em = wh: GOSUB Asearch2
  IF F = 0 THEN
    PRINT "I don't follow you.": GOTO Main0
  END IF
  IF a%(m, 6) = 0 THEN GOTO Err2
  GOSUB ItemTake: IF a%(a, 4) <> -1 THEN a%(a, 4) = ro
  a%(m, 7) = a%(m, 7) - 1: IF a%(m, 7) < 0 THEN a%(m, 7) = 0
  PRINT "Okay."
  GOTO Pfoe
'---------------------------------------------------------------------------
' **** Use command ****
'
' Put your own special stuff here
'
Use:
  IF lt = 0 THEN GOTO Main
  GOSUB CheckSub: ha = -1: wh = ro: em = -999: GOSUB Asearch2
  IF F = 0 THEN GOTO Err1
  IF a = 47 AND m%(37, 5) = ro THEN m = 37: GOTO Give1
  IF a = 44 THEN r = 104: GOTO Lp20
  IF a <> 12 AND a <> 30 THEN PRINT "Try another command.": GOTO Lp12
  IF a = 30 THEN
    IF ro = 2 AND a%(31, 6) = -1 THEN
      a%(31, 6) = 0: a%(31, 7) = 0: r = 63: GOTO Lp20
    END IF
    PRINT "Nobody seems impressed.": GOTO Lp12
  END IF
  SOUND 200, 2: COLOR 2: PRINT "ACCESSING DATA FILES...": PRINT
  PRINT "(Type the subject to ask about or Enter to leave)"
Cpt:
  PRINT : PRINT : LINE INPUT "]"; a$: F = 0: a$ = LTRIM$(RTRIM$(LCASE$(a$)))
  IF a$ = "" THEN PRINT "SESSION TERMINATED.": COLOR 3: l = 99: GOTO Lp12
  sl = LEN(a$): s$ = "rocket":
  IF LEFT$(s$, sl) = a$ OR RIGHT$(s$, sl) = a$ THEN F = 1
  sl = LEN(a$): s$ = "code":
  IF LEFT$(s$, sl) = a$ OR RIGHT$(s$, sl) = a$ THEN F = 1
  IF F = 0 THEN PRINT e$(INT(RND * 6) + 1): SOUND 900, 2: GOTO Cpt
  PRINT "(Rocket launch codes)  Try this one:": PRINT
  PRINT "#1 = 12,  #2 = 9,  #3 = 76": GOTO Cpt




'---------------------------------------------------------------------------
' **** Wear command ****
'
Wear:
  GOSUB CheckSub: ha = -1: wh = ro: em = -999: GOSUB Asearch2
  IF F = 0 THEN GOTO Err1
  IF a%(a, 4) = ro THEN
    GOSUB ItemTake: IF a%(a, 4) <> -1 THEN GOTO Main
  END IF
  IF a%(a, 2) <> 11 THEN
    s$ = "that": GOTO Err3
  END IF
  IF a%(a, 4) = em THEN GOTO Wear2
  IF a%(a, 5) = 0 THEN GOTO Wear1
  IF a%(a, 5) = 1 AND sh > 0 THEN GOTO Wear2
  IF a%(a, 5) = 1 THEN
    sh = a: m%(0, 7) = m%(0, 7) + 1: GOTO Wear1
  END IF
  IF ar <> 0 THEN GOTO Wear2
  ar = a: m%(0, 7) = m%(0, 7) + a%(a, 5) / 2
Wear1:
  a%(a, 4) = -999
  PRINT UCASE$(LEFT$(a$(a), 1)); MID$(a$(a), 2); " worn."
  GOTO Pfoe
Wear2:
  PRINT "You're already wearing armor of that type!": GOTO Main0
'---------------------------------------------------------------------------
'  **** Attack command ****
'
Attack:
  IF m%(0, 8) < 1 THEN
    PRINT "You must first ready a weapon!": GOTO Main0
  END IF
  IF m%(0, 8) = 32 THEN
    r = 27: GOSUB Effect: m%(0, 13) = m%(0, 1) - 1: m%(0, 8) = -1: df = 0
    a%(32, 4) = 0: wt = wt - a%(32, 3): d2 = 0: GOSUB Mstatus: GOTO Pfoe
  END IF
  GOSUB CheckSub:  GOSUB Msearch: ta = 0: IF F THEN GOTO Attackmon
'
'  Attack/blast open a door or container
'
AttackItem:
  IF lt = 0 THEN GOTO Main
  ha = ro: GOSUB Asearch1: IF F = 0 THEN GOTO Err4
  IF a = 31 THEN
    a%(m%(0, 8), 4) = 0: wt = wt - a%(m%(0, 8), 3): m%(0, 8) = -1
    r = 22: GOTO Lp20
  END IF
  IF db > 0 AND a >= db AND a <= naf THEN
    PRINT "You hack the body to bits!": a%(a, 4) = 0: GOTO Pfoe
  END IF
  m = a%(a, 2)
  IF m = 12 THEN
    GOSUB ItemGet3: m = a%(a, 5): GOTO Attackmon
  END IF
  IF m <> 4 AND m <> 8 THEN PRINT "Control yourself.": GOTO Main0
  IF (m = 8 AND a%(a, 7) < 100) OR (m = 4 AND a%(a, 6) < 100) THEN
    PRINT "Nothing happens.": GOTO Lp12
  END IF
  w = m%(0, 8): d = a%(w, 7): s = a%(w, 8): x = 7: k = 6: d2 = 0
  IF ta = 1 THEN
    d = 2: s = 5
  END IF
  IF m = 4 THEN
    x = 6: k = 5
  END IF
  FOR a2 = 1 TO d
     d2 = d2 + INT(RND * s) + 1
  NEXT
  a$ = "Wham!  You " + MID$("hitblast", ta * 3 + 1, 3 + ta * 2)
  a$ = a$ + " the " + a$(a) + "!": GOSUB Lp10
  a%(a, x) = a%(a, x) - d2
  IF a%(a, x) < 100 THEN
    a%(a, x) = 1: a%(a, k) = 0: a$ = "The " + a$(a) + " shatters open!"
    IF m = 8 THEN
      a%(a, 6) = 0: a%(a, 7) = 0
    END IF
    GOTO Lp9
  END IF
  GOTO Pfoe
'
' Attack a monster
'
Attackmon:
  r3 = ro
  IF m%(m, 11) <> 1 THEN GOSUB AtFr: IF s$ <> "y" THEN GOTO Main
  IF m = 42 OR m = 43 OR m = d%(8) THEN PRINT "Dream on.": GOTO Lp12
  IF ro = 3 AND (m = 31 OR m = 32 OR m = 33) AND m%(m, 11) > 1 THEN
    m%(31, 11) = 1: m%(32, 11) = 1: m%(33, 11) = 1: m%(38, 11) = 1
    IF m%(38, 5) = 2 THEN m%(38, 5) = 3
    GOSUB EnemyCheck: COLOR 2: PRINT "You just started a riot!"
    COLOR 3: GOSUB Lp4
  END IF
  IF m = 39 AND m%(m, 11) > 1 THEN
    d%(3) = 0: m%(m, 11) = 1: GOSUB EnemyCheck
    COLOR 2: PRINT q$; "Hey!  Wush yer problem, pal?"; q$: COLOR 3: GOSUB Lp4
  END IF
  IF m = 17 AND m%(m, 11) > 1 THEN
    PRINT m$(m); " starts to laugh...": GOSUB Lp4: m%(m, 11) = 1: GOSUB EnemyCheck
  END IF
  IF m = 22 AND m%(m, 11) > 1 THEN
    m%(m, 11) = 1: GOSUB EnemyCheck: COLOR 2
    PRINT m$(m); " says, "; q$; "Another notch for my axe, eh?"; q$
    COLOR 3: GOSUB Lp4
  END IF
  IF m%(m, 11) > 1 THEN
    a$ = m$(m) + " screams, " + q$ + "Hey!  What's the matter with you!?!" + q$
    GOSUB Lp10: m%(m, 11) = 1
    FOR xm = 3 TO nm
       IF m%(xm, 11) > 1 AND m%(xm, 5) = ro AND xm <> 42 AND xm <> 43 THEN
         a$ = m$(xm) + " get's angry!": GOSUB Lp10: m%(xm, 11) = 1
       END IF
    NEXT
    GOSUB EnemyCheck
  END IF
  of = 0: df = m: up = 0: GOSUB Battle
  IF die = 1 THEN GOTO EndGame
  IF hi = 1 AND up = 1 THEN
    w2 = a%(m%(0, 8), 6)
    a$ = m$(0) + MID$("'s'", ABS(LCASE$(RIGHT$(m$(0), 1)) = "s") * 2 + 1, 2)
    a$ = a$ + " " + wp$(w2) + " ability just increased!"
    wa%(w2) = wa%(w2) + 1: GOSUB Lp0: GOSUB Lp1
  END IF
  IF m%(df, 11) = 1 OR df = 0 THEN GOTO Pfoe
  m%(df, 11) = m%(df, 11) - 1
  GOSUB EC: GOTO Pfoe
'---------------------------------------------------------------------------
' **** Free command ****
'
Free:
  IF lt = 0 THEN GOTO Main
  GOSUB CheckSub: GOSUB Asearch0: IF F = 0 THEN GOTO Err4
  IF a%(a, 2) <> 10 THEN GOTO Err3
  m = a%(a, 5): k = a%(a, 6): w = a%(a, 7)
  IF w > 0 AND w <= nm THEN
    IF m%(w, 5) = ro THEN
      PRINT m$(w); " won't let you!": GOTO Lp12
    END IF
  END IF
  IF k > 0 AND k <= naf THEN
    IF a%(k, 4) <> -1 AND a%(k, 4) <> ro AND a%(k, 4) <> -999 THEN
      PRINT "You don't have the key.": GOTO Lp12
    END IF
  END IF
  a$ = "You have freed " + m$(m)
  IF k > 0 AND k <= naf THEN a$ = a$ + " with the " + a$(k)
  a$ = a$ + ".": GOSUB Lp0
  m%(m, 5) = ro: a%(a, 4) = 0: r3 = ro
  IF m = 23 THEN d%(30) = 1
  GOSUB EnemyCheck: GOTO Pfoe
'---------------------------------------------------------------------------
' **** Give command ****
'
Give:
  IF lt = 0 THEN GOTO Main
  GOSUB CheckSub: k = ABS(INT(VAL(s$)))
  IF k = 0 THEN
    GOSUB Asearch0
    IF F = 0 THEN
      ha = -999: wh = ha: em = ha: GOSUB Asearch2: IF F = 0 THEN GOTO Err1
      PRINT "You're wearing it.  "; q$; "REMOVE"; q$; " it first.": GOTO Main0
    END IF
    GOSUB ItemTake: IF a%(a, 4) <> -1 THEN GOTO Main
  END IF
  a$ = "To whom": GOSUB CheckSub2
  s$ = s2$: GOSUB Msearch: IF F = 0 THEN GOTO Err4
  IF m = 42 OR m = 43 THEN PRINT "He doesn't notice you.": GOTO Lp12
  IF k = 0 THEN GOTO Give1
'
' Give money
'
GiveMoney:
  s2$ = "": a$ = "Give " + LTRIM$(STR$(k)) + "GP to "
  a$ = a$ + m$(m) + " (Y/N)": GOSUB CheckSub2
  s2$ = LEFT$(s2$, 1): IF s2$ <> "y" AND s2$ <> "n" THEN GOTO GiveMoney
  IF s2$ = "n" THEN GOTO Main
  IF gold < k THEN PRINT "You only have"; gold; "gold pieces.": GOTO Main0
  IF m = 6 AND k < 100 AND d%(2) = 1 THEN PRINT "He wants more!": GOTO Lp12
  IF m = 22 AND k < 300 AND d%(52) = 0 THEN PRINT "He wants more!": GOTO Lp12
  IF (m%(m, 11) = 1 OR m = 39) AND m <> 6 THEN
    COLOR 2: PRINT m$(m); " grabs ALL of your money!": COLOR 3
    gold = 0: GOTO Lp12
  END IF
  IF m = 4 AND k <> 500 AND m%(m, 11) <> 3 THEN
    PRINT "He wants 500 gold pieces.  No more, no less.": GOTO Lp12
  END IF
  IF m = 35 THEN
    IF ro <> 6 THEN PRINT "She doesn't notice you.": GOTO Lp12
    IF k <> 50 THEN PRINT q$; "My rent is 50 gold pieces."; q$: GOTO Lp12
    IF m%(2, 5) = ro THEN r = 71: GOTO Lp20
  END IF
  IF m = 37 AND d%(32) = 1 AND k <> 50 THEN
    PRINT q$; "I said 50 gold pieces!"; q$: GOTO Lp12
  END IF
  IF m = 37 AND a%(37, 6) = 0 AND a%(38, 0) = 1 AND k <> 200 THEN
    PRINT q$; "I said 200 gold pieces!"; q$: GOTO Lp12
  END IF
  IF m = 3 THEN r = 23: GOSUB Effect: m%(3, 11) = 2: GOTO Pfoe
  IF m = 33 THEN r = 24: GOTO Lp20
  IF m = 32 AND (k < 2 OR k > 5) THEN
    r = 25 + ABS(k > 5): GOTO Lp20
  END IF
  IF m = 32 AND a%(42, 7) > 7 THEN
    PRINT q$; "You had enough last night."; q$: GOTO Lp12
  END IF
'
  gold = gold - k: a$ = m$(m) + " takes the money.": GOSUB Lp10
'
  IF m = 4 AND m%(m, 11) = 2 THEN
    m%(m, 11) = 3: PRINT q$; "I'm at your service."; q$: GOTO Lp12
  END IF
  IF m = 6 AND d%(2) = 1 THEN
    d%(2) = 2: m%(m, 5) = 44: m%(m, 11) = 2: r = 21: GOSUB Effect
    PRINT "The Customs Offical leaves.": GOSUB EC: GOTO Lp12
  END IF
  IF m = 22 AND d%(52) = 0 THEN
    d%(52) = 1: GOSUB Smile1: GOSUB Lp1: PRINT m$(m); " says, ";
    PRINT q$; "You may pass."; q$: GOTO Lp12
  END IF
  IF m = 35 THEN
    PRINT q$; "Oh, thank you!"; q$: GOSUB Lp4: m%(m, 11) = 3: m%(35, 5) = 54
    d%(4) = 0: a%(45, 6) = 0: a%(45, 7) = 0: r = 97: GOTO Lp20
  END IF
  IF m = 37 AND d%(32) = 1 THEN
    FOR a = 1 TO na
       IF a%(a, 0) = 5 THEN a%(a, 0) = 1
    NEXT
    d%(32) = 0:   PRINT q$; "Nice doin' business with you!": GOTO Lp12
  END IF
  IF m = 37 THEN
    IF a%(37, 5) = 0 THEN PRINT q$; "Sure, kid."; q$: GOTO Lp12
    IF a%(37, 6) = 0 THEN
      a%(37, 6) = 1: PRINT q$; "It's all yours!"; q$: GOTO Lp12
    END IF
  END IF
  IF m = 32 THEN
    IF a%(42, 5) > 0 THEN PRINT q$; "Finish what you got."; q$: GOTO Lp12
    x = (k - 2) * 12 + 1
    a$ = MID$("beer        ale         Death's Griproot beer", x, 12)
    a$(42) = "mug of " + RTRIM$(a$): a%(42, 5) = 2: a%(42, 6) = k
    a%(42, 4) = ro: r = 29: GOTO Lp20
  END IF
  IF m%(m, 11) = 3 THEN PRINT m$(m); " says, "; q$; "Thanks!"; q$: GOTO Lp12
  IF m%(m, 11) = 2 AND k >= 50 THEN
    m%(m, 11) = 3: GOSUB Smile1
  END IF
  GOTO Give2
'
' Give an item
'
Give1:
  IF m = 35 THEN GOSUB Smile1: GOTO Pfoe
  IF m = 17 AND a <> 10 THEN PRINT m$(m); " doesn't want that.": GOTO Lp12
  IF m = 32 OR (m = 34 AND a <> 48) THEN r = 69: GOTO Lp20
  IF m = 37 AND a <> 47 THEN r = 70: GOTO Lp20
  IF a = 30 AND m = 38 THEN s$ = "i.d.": GOTO Use
'
  a$ = "You give the " + a$(a) + " to " + m$(m) + ".": GOSUB Lp0: GOSUB Lp1
  IF a = m%(0, 8) THEN m%(0, 8) = -1
  IF a%(a, 2) = 6 THEN
    IF m%(m, 13) > 0 AND a%(a, 6) > 0 THEN GOTO GiveDrink
  END IF
  wt = wt - a%(a, 3) * (a%(a, 4) = -1)
  a%(a, 4) = -m - 1
'
  IF m = 17 THEN
    r = 13: GOSUB Effect: GOSUB Lp6
    FOR a = 2000 TO 200 STEP -85: SOUND a, 1: NEXT
    FOR a = 200 TO 2000 STEP 85: SOUND a, 1: NEXT
    FOR a = 2000 TO 200 STEP -85: SOUND a, 1: NEXT
    FOR a = 200 TO 2000 STEP 85: SOUND a, 1: NEXT
    r2 = 19: GOTO Move2
  END IF
  IF m = 34 THEN
    a%(a, 4) = 0: gold = gold1: r = 102: GOSUB Effect
    PRINT "He pays you "; LTRIM$(RTRIM$(STR$(gold1))); " gold pieces."
    GOTO Lp12
  END IF
  IF m = 37 THEN d%(32) = 1: r = 101: GOTO Lp20
  IF m%(m, 8) < 0 THEN
    IF a%(a, 2) = 2 OR a%(a, 2) = 3 THEN
      m%(m, 8) = a: a$ = m$(m) + " readies " + a$(a) + ".": GOSUB Lp0
    END IF
  END IF
  IF m%(m, 11) < 3 THEN m%(m, 11) = 100 + m%(m, 11) * (30 + a%(a, 1) / 100)
Give2:
  GOSUB EC: GOTO Pfoe
'
' Give something drinkable
'
GiveDrink:
  a$ = m$(m) + " takes a drink and hands it back to you.": GOSUB Lp0
  GOSUB Lp1: a%(a, 6) = a%(a, 6) - 1
  IF m%(m, 11) < 3 THEN m%(m, 11) = 140 + 60 * m%(m, 13) / m%(m, 1)
  m%(m, 13) = m%(m, 13) - a%(a, 5): IF m%(m, 13) < 0 THEN m%(m, 13) = 0
  df = m: d2 = 0: GOSUB Mstatus: GOTO Give2
'---------------------------------------------------------------------------
' **** Request command ****
'
Request:
  IF lt = 0 THEN GOTO Main
  GOSUB CheckSub: a$ = "Pester whom for it": GOSUB CheckSub2
  a$ = s$: s$ = s2$: GOSUB Msearch: IF F = 0 THEN GOTO Err4
  IF m = 42 OR m = 43 THEN PRINT "He doesn't notice you.": GOTO Lp12
  s$ = a$: wh = -m - 1: ha = -m - 1000: em = wh: GOSUB Asearch2
  IF F = 0 THEN
    PRINT m$(m); " doesn't have it.": GOTO Main0
  END IF
  IF m%(m, 11) < 2 OR (m%(m, 11) < 3 AND m <> 6) THEN
    GOSUB Smile1: GOTO Pfoe
  END IF
  IF m = 6 AND a <> 27 THEN
    PRINT q$; "I'll give it to you for 50 gold pieces."; q$: GOSUB Lp4
    IF gold < 50 THEN PRINT "You don't have that much.": GOTO Lp4
    PRINT "Pay the money"; : GOSUB AtFr1: IF s$ <> "y" THEN GOTO Pfoe
    gold = gold - 50
  END IF
  IF a = 24 AND m = 26 THEN PRINT m$(m); " refuses.": GOTO Lp12
'
' All mons except A.J. and C.O. won't give up weapon unless they have
'    another (Unless the weapon belongs to player)
'
  IF (a = m%(m, 8) AND m <> 2 AND m <> 6 AND a <= naf) OR (m = 6 AND a = 27) THEN
    F = 0
    FOR x = 1 TO na
       r = a%(x, 2)
       IF a%(x, 4) = -m - 1 AND x <> a AND (r = 2 OR r = 3) THEN F = 1
    NEXT
    IF F = 0 THEN PRINT m$(m); " says:": GOSUB Lp4: r = 57: GOTO Lp20
  END IF
'
  PRINT "Okay.": GOSUB Lp4
  GOSUB ItemGet3
  IF a%(a, 4) = -1 THEN
    IF a = m%(m, 8) THEN m%(m, 8) = -1
    IF a%(a, 0) = 0 THEN
      a%(a, 0) = 1: GOSUB Lp1: r = a + 400: GOSUB DiskRead
    END IF
  END IF
  GOTO Pfoe
'---------------------------------------------------------------------------
' **** Smile command ****
'
Smile:
  IF lt = 0 THEN GOTO Main
  FOR m = 1 TO nm
     IF m%(m, 5) = ro THEN GOSUB Smile1
  NEXT: GOTO Pfoe
Smile1:
  PRINT m$(m); : IF m = 17 THEN PRINT " is not amused.": GOTO Lp2
  IF m = 42 OR m = 43 THEN PRINT " ignores you.": GOTO Lp2
  IF m%(m, 3) > 1 THEN PRINT "s";
  a$ = sm$(m%(m, 11)): IF m = 2 AND m%(m, 11) = 3 THEN a$ = "grin"
  PRINT " "; a$; : IF m%(m, 3) = 1 THEN PRINT "s";
  PRINT " at you.": GOTO Lp2
'---------------------------------------------------------------------------
' **** Inventory command ****
'
Inventory:
  IF s$ = "" THEN GOTO Inv1
  IF lt = 0 THEN GOTO Main
  GOSUB CheckSub: GOSUB Msearch: IF F = 0 THEN GOTO Err4
  IF m%(m, 11) > 1 THEN GOTO Inv2
  GOSUB Smile1: GOTO Pfoe
Inv1:
  m = 0: m2 = 0: PRINT m$(m); " is wearing:": GOSUB Lp4
  FOR a = 1 TO na
     IF a%(a, 4) = -999 THEN
       PRINT " "; UCASE$(LEFT$(a$(a), 1)); MID$(a$(a), 2)
       m2 = 1: GOSUB Lp2
     END IF
  NEXT
  IF m2 = 0 THEN PRINT " (No armor)": GOSUB Lp2
  GOSUB Lp1
Inv2:
  F = 0: PRINT m$(m); " is carrying:": GOSUB Lp4
  ha = -m - 1: wh = -m - 1000: IF m = 0 THEN wh = ha
  FOR a = 1 TO na
     IF a%(a, 4) = ha OR a%(a, 4) = wh THEN
       PRINT " "; UCASE$(LEFT$(a$(a), 1)); MID$(a$(a), 2);
       IF m > 0 AND a%(a, 4) = wh THEN PRINT "  (Being worn)";
       IF a = m%(m, 8) THEN COLOR 2: PRINT "   [Ready Weapon]"; : COLOR 3
       IF a = ls THEN COLOR 2: PRINT "  (Providing light)"; : COLOR 3
       IF a%(a, 2) = 4 THEN GOSUB Inv3
       F = 1: GOSUB Lp1
     END IF
  NEXT
  IF F = 0 THEN
    PRINT " (Nothing)": GOSUB Lp4
  END IF
  IF m = 0 THEN
    PRINT LTRIM$(STR$(gold)); " gold pieces": GOSUB Lp4
  END IF
  df = m: d2 = 0: GOSUB Mstatus: GOTO Pfoe
'
' Show items inside of container
'
Inv3:
  IF a%(a, 6) <> 1 THEN
    PRINT "  (Closed)"; : RETURN
  END IF
  GOSUB Lp1
Inv4:
  m2 = 0: PRINT "(This contains:)": GOSUB Lp2: of = 0
  FOR a2 = 1 TO na
     IF a%(a2, 4) = a + 1000 THEN
       PRINT " --- "; UCASE$(LEFT$(a$(a2), 1)); MID$(a$(a2), 2)
       GOSUB Lp2: of = 1
     END IF
  NEXT
  IF of = 0 THEN
    PRINT " --- (Nothing)": GOSUB Lp2
  END IF
  RETURN
'---------------------------------------------------------------------------
' **** Status command ****
'
Status:
  CLS : l = 0
  FOR a = 1 TO 4
     sa$(a) = LTRIM$(STR$(sa%(a))) + "%": sp$(a) = LTRIM$(STR$(sp%(a))) + "%"
  NEXT
  IF sex < 0 OR sex > 1 THEN sex = 0
  PRINT "Name: "; LEFT$(m$(0), 32); : LOCATE CSRLIN, 40
  PRINT "Sex: "; sex$(sex); : LOCATE CSRLIN, 55
  a$ = STR$(m%(0, 13)) + "/" + LTRIM$(STR$(m%(0, 1)))
  PRINT "Damage Taken:"; a$: PRINT
  PRINT "Hardiness: "; m%(0, 1): LOCATE 3, 20: PRINT "Agility: "; m%(0, 2)
  LOCATE 3, 37: PRINT "Charisma: "; ch;
  PRINT "   (Charm Mon:"; : a = (ch - 10) * 2: a$ = LTRIM$(STR$(a)) + "%)"
  PRINT MID$("+", ABS((a < 1)) * 1 + 1, 1); a$: PRINT
  PRINT "Weapon Abilities:"; : LOCATE 5, 41: PRINT "Spell Abilities:"
  PRINT "1. Axe:  "; wa%(1);
  LOCATE 6, 42: PRINT "Blast.."; : a = 1: GOSUB Status1
  PRINT "2. Bow:  "; wa%(2);
  LOCATE 7, 42: PRINT "Heal..."; : a = 2: GOSUB Status1
  PRINT "3. Mace: "; wa%(3);
  LOCATE 8, 42: PRINT "Speed.."; : a = 3: GOSUB Status1
  PRINT "4. Spear:"; wa%(4);
  LOCATE 9, 42: PRINT "Power.."; : a = 4: GOSUB Status1
  PRINT "5. Sword:"; wa%(5); : LOCATE 10, 22: PRINT "Gold:"; gold
  IF loan > 0 THEN LOCATE 10, 40: COLOR 2: PRINT "Owed:"; loan: COLOR 3
  LOCATE 10, 58: PRINT "In bank:"; bank: PRINT
  PRINT "Armor: ";
  IF ar > 1 AND ar <= na THEN PRINT UCASE$(LEFT$(a$(ar), 1)); MID$(a$(ar), 2);
  IF sh > 1 AND sh <= na AND ar > 1 AND ar <= na THEN PRINT " & ";
  IF sh > 1 AND sh <= na THEN PRINT UCASE$(LEFT$(a$(sh), 1)); MID$(a$(sh), 2);
  a$ = RTRIM$(STR$(ae)) + "%"
  PRINT : LOCATE 12, 41: PRINT "  Armor Expertise: "; a$
  PRINT : PRINT "Weight Carryable:"; m%(0, 1) * 10; "Gronds  (";
  a$ = LTRIM$(RTRIM$(STR$(a * 10))): PRINT a$; " Dos)": LOCATE 14, 43
  s$ = LTRIM$(RTRIM$(STR$(wt))): PRINT "  Weight carried:"; wt; "Gronds"
  PRINT : x = a%(42, 7)
  IF x > 0 AND x < 5 THEN PRINT "You have a slight buzz.";
  IF x > 4 AND x < 8 THEN
    PRINT "Your head is spinning and your mouth is numb.";
  END IF
  PRINT : PRINT
  LOCATE 22: GOSUB Lp6: CLS : LOCATE 24: GOTO Main
Status1:
  m = sa%(a)
  PRINT LEFT$("...", ABS(m < 1000) + ABS(m < 100) + ABS(m < 10));
  IF m <> sp%(a) THEN COLOR 2
  PRINT sa$(a); : COLOR 3: PRINT " / "; sp$(a)
  RETURN
'---------------------------------------------------------------------------
'  **** Look command ****
'
Look:
  IF lt = 0 THEN GOTO Main
  r = ro: GOSUB DiskRead: GOTO Pfoe
'---------------------------------------------------------------------------
' **** Say command ****
'
Say:
  GOSUB CheckSub: s$ = LTRIM$(RTRIM$(LEFT$(s$, 60)))
  s$ = UCASE$(LEFT$(s$, 1)) + LCASE$(MID$(s$, 2))
  a$ = "Okay, " + q$ + LEFT$(s$, 60) + q$ + ".": GOSUB Lp10
  IF s$ = "+bye" THEN r2 = -999: GOTO MoveCheck
  IF s$ = "+go" THEN INPUT "Room#"; r2: IF r2 > 0 AND r2 <= nr THEN GOTO Move2
  IF s$ = "+info" THEN PRINT "Thugs are"; d%(8); "at"; d%(10): GOTO Main0
  IF s$ = "+maze" THEN
    IF ro < 32 OR ro > 35 THEN PRINT "You aren't in the maze.": GOTO Main0
    PRINT "Leaving maze...": GOSUB Lp4: r2 = 36: GOTO Move2
  END IF
  IF ro = 2 AND a%(31, 6) = -1 THEN
    PRINT q$; "That's not the password!"; q$: GOTO Pfoe
  END IF
  IF m%(1, 5) = ro THEN
    PRINT m$(1); " says:": GOSUB Lp4: r = 1: GOSUB Effect
  END IF
  GOTO Pfoe
'---------------------------------------------------------------------------
' **** Blast command ****
'
Blast:
  s = 1: GOSUB SpellCast: IF suc = 0 THEN GOTO Pfoe
  GOSUB CheckSub: GOSUB Msearch: ta = 1: IF F = 0 THEN GOTO AttackItem
  IF m%(m, 11) <> 1 THEN
    GOSUB AtFr: IF s$ <> "y" THEN GOTO Main
    sa%(1) = 0: r = 95: GOTO Lp20
  END IF
  FOR a = 600 TO 100 STEP -20: SOUND a, 1: NEXT
  PRINT "ZAP!  Direct hit!": GOSUB Lp4
  s = 5: d = 2: df = m: a = 0: GOSUB Damage0: GOTO Pfoe
'---------------------------------------------------------------------------
' **** Heal command ****
'
Heal:
  s = 2: GOSUB SpellCast: m = 0: IF suc = 0 THEN GOTO Pfoe
  IF s$ <> "" THEN GOSUB Msearch: IF F = 0 THEN GOTO Err4
  IF m = 42 OR m = 43 THEN GOSUB Smile1: GOTO Pfoe
  IF m%(m, 13) > 0 THEN
    a$ = m$(m) + MID$("'s'", ABS(LCASE$(RIGHT$(m$(0), 1)) = "s") * 2 + 1, 2)
    a$ = a$ + " health improves!": GOSUB Lp0
    m%(m, 13) = m%(m, 13) - 3 - 10 * RND
    IF m%(m, 13) < 0 THEN m%(m, 13) = 0
  END IF
  df = m: d2 = 0: GOSUB Mstatus: GOTO Pfoe
'---------------------------------------------------------------------------
' **** Speed command ****
'
speed:
  s = 3: GOSUB SpellCast: IF suc = 0 THEN GOTO Pfoe
  IF speed <> 0 THEN PRINT "Nothing happened.": GOTO Lp12
  m%(0, 2) = m%(0, 2) * 2: speed = INT(RND * 10 + 26)
  PRINT "Your agility temporarily increases!"
  GOTO Lp12
'---------------------------------------------------------------------------
' **** Power command ****
'
Power:
  s = 4: GOSUB SpellCast: IF suc = 0 THEN GOTO Pfoe
  IF ro = 12 THEN
    r = 11: GOSUB Effect: GOSUB Lp6: COLOR 2: a$ = "But wait ... What's this?"
    FOR a = 1 TO LEN(a$)
       PRINT MID$(a$, a, 1);
       FOR m# = 1 TO dly# / 2: NEXT
    NEXT: FOR m# = 1 TO dly# * 3: NEXT
    GOSUB Power1: a$(naf + 1) = "wet noodle"
    FOR a = naf + 2 TO na: a$(a) = a$(a - 1) + "#": NEXT
    m$(0) = "Joe Average": gold = gold + RND * 32: r = 10: GOSUB Effect
    r = 89: GOSUB Effect: GOSUB Lp6: r2 = 13: GOTO Move2
  END IF
  IF ro > 12 AND ro < 22 THEN PRINT "power...power...power??": GOTO Lp12
  IF ro > 21 AND ro < 39 AND r%(53, 0) = 0 THEN
    d%(35) = 1: r = 96: GOSUB Effect: GOSUB Lp6: r2 = 53: GOTO Move2
  END IF
  IF ro > 21 AND ro < 39 THEN
    a$ = "SHAZAM!!  BOOM!!  CRASH...RUMBLE!!!"
    FOR a = 1 TO LEN(a$)
      PRINT MID$(a$, a, 1); : FOR m# = 1 TO dly# / 2: NEXT
    NEXT: PRINT : GOSUB Lp4: PRINT "Nothing happens.": GOTO Lp12
  END IF
  PRINT "You hear a very familiar sonic boom which echoes all around you!"
  GOTO Lp12
Power1:
  a$ = "/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\": WIDTH 40
  FOR x = 1 TO 50
     CLS : LOCATE 24: COLOR 0, INT(RND * 15) + 1
     FOR a = 1 TO 10: PRINT a$: PRINT : PRINT a$: NEXT
     SOUND 8000 - x * 50, 1
  NEXT
  COLOR 3, 0: WIDTH 80: CLS : LOCATE 24: l = 0: RETURN
'---------------------------------------------------------------------------
' **** Hints command ****
'
Hints:
  PRINT "Your question?": GOSUB Lp4
  FOR r = 1 TO nh
     IF r < 10 THEN PRINT " ";
     PRINT r; "- "; h$(r): GOSUB Lp2
  NEXT
  GOSUB Lp1: LINE INPUT "Your choice?:"; a$: l = 0
  r = INT(VAL(a$)): IF r < 1 OR r > nh THEN GOTO Main
  GOSUB Lp1: COLOR 2: PRINT h$(r): COLOR 3: GOSUB Lp4
  OPEN "HINTS.DSC" FOR RANDOM AS #2 LEN = 255
  a = h%(r, 1) + h%(r, 2) - 1: s$ = ""
  FOR m = h%(r, 1) TO a
     GET #2, m, DS: a$ = RTRIM$(DS.TEXT): GOSUB Lp10
     IF m < a THEN
       PRINT "Another? (Y/N):";
       DO
       s$ = LCASE$(INKEY$)
       LOOP UNTIL s$ <> ""
       LOCATE CSRLIN, 1: PRINT "               "; : LOCATE CSRLIN, 1: l = 0
       IF s$ <> "y" THEN m = a
     END IF
  NEXT
  CLOSE #2: GOTO Main0
'---------------------------------------------------------------------------
' **** Save game ****
'
GameSave:
OPEN "GAMEDIR.DAT" FOR INPUT AS #2
INPUT #2, a
IF a < 0 THEN a = 0
FOR m = 1 TO 5
   LINE INPUT #2, gm$(m)
NEXT: CLOSE #2
PRINT "Saved games:": GOSUB Lp4
FOR m = 1 TO 5
   PRINT m; " - "; gm$(m): GOSUB Lp2
NEXT
PRINT 6; " - (Don't save, return to game)": GOSUB Lp2: GOSUB Lp1
INPUT "Enter 1-6 for saved position:"; a$
m = INT(VAL(a$))
IF m < 1 OR m > 6 THEN GOTO GameSave
IF m = 6 THEN GOTO Main
IF m > a + 1 THEN
  PRINT "Use #"; a + 1; "first.": GOSUB Lp4: GOTO GameSave
END IF
IF m = a + 1 THEN a = a + 1
IF gm$(m) <> "(none)" THEN
  PRINT "Enter a new description for save?"; : GOSUB AtFr1
  IF s$ <> "y" THEN GOTO GameSave1
END IF
PRINT "Enter new description:": GOSUB Lp4
LINE INPUT "-->"; gm$(m): l = 1
GameSave1:
OPEN "GAMEDIR.DAT" FOR OUTPUT AS #2
PRINT #2, a
FOR k = 1 TO 5: PRINT #2, gm$(k): NEXT: CLOSE #2
a$ = "GAME" + LTRIM$(RTRIM$(STR$(m))) + ".SAV"
OPEN a$ FOR OUTPUT AS #2
FOR a = 1 TO na
   FOR m = 0 TO 8
      PRINT #2, a%(a, m)
   NEXT
NEXT
FOR m = 0 TO nm
   FOR a = 0 TO 15
      PRINT #2, m%(m, a)
   NEXT
NEXT
FOR r = 1 TO nr
   FOR m = 0 TO 11
      PRINT #2, r%(r, m)
   NEXT
NEXT
FOR a = 1 TO 4
   PRINT #2, t(a), sa%(a), sp%(a)
NEXT
FOR a = 1 TO 5
   PRINT #2, wa%(a)
NEXT
FOR a = 1 TO 200: PRINT #2, d%(a): NEXT
PRINT #2, ac, ae, ar, bank, ch, die, ea, gold, ls, lt, nl, r3, ro, sex, sh
PRINT #2, speed, wt, r4, gold1, loan
PRINT #2, m$(0)
PRINT #2, a$(42)
FOR a = naf + 1 TO na
   PRINT #2, a$(a)
NEXT
CLOSE #2
PRINT "Game saved.": GOSUB Lp4: GOTO Main
'---------------------------------------------------------------------------
' **** Restore saved game ****
'
GameRestore:
  OPEN "GAMEDIR.DAT" FOR INPUT AS #2
  INPUT #2, a
  FOR m = 1 TO 5
     LINE INPUT #2, gm$(m)
  NEXT: CLOSE #2
  PRINT "Saved games:": GOSUB Lp4
  FOR m = 1 TO 5
     PRINT m; " - "; gm$(m): GOSUB Lp2
  NEXT: PRINT 6; " - (Don't restore, return to game)": GOSUB Lp2: GOSUB Lp1
  INPUT "Enter 1-6 to restore a position:"; a$
  m = INT(VAL(a$))
  IF m < 1 OR m > 6 THEN GOTO GameRestore
  IF m = 6 THEN
    IF die = 1 THEN GOTO Dead
    GOTO Main
  END IF
  IF m > a THEN
    PRINT "There is no saved game there.": GOSUB Lp4: GOTO GameRestore
  END IF
  a$ = "GAME" + LTRIM$(RTRIM$(STR$(m))) + ".SAV"
  OPEN a$ FOR INPUT AS #2
  FOR a = 1 TO na
     FOR m = 0 TO 8
        INPUT #2, a%(a, m)
     NEXT
  NEXT
  FOR m = 0 TO nm
     FOR a = 0 TO 15
        INPUT #2, m%(m, a)
     NEXT
  NEXT
  FOR r = 1 TO nr
     FOR m = 0 TO 11
        INPUT #2, r%(r, m)
     NEXT
  NEXT
  FOR a = 1 TO 4
     INPUT #2, t(a), sa%(a), sp%(a)
  NEXT
  FOR a = 1 TO 5
     INPUT #2, wa%(a)
  NEXT
  FOR a = 1 TO 200
     INPUT #2, d%(a)
  NEXT
  INPUT #2, ac, ae, ar, bank, ch, die, ea, gold, ls, lt, nl, r3, ro, sex, sh
  INPUT #2, speed, wt, r4, gold1, loan
  INPUT #2, m$(0)
  INPUT #2, a$(42)
  FOR a = naf + 1 TO na
     INPUT #2, a$(a)
  NEXT
  CLOSE #2
  cz$ = "": r2 = ro: GOTO Move2
'---------------------------------------------------------------------------
' **** Quit, leave the Eamon system ****
'
Quit:
  OPEN "GAMEDIR.DAT" FOR INPUT AS #2: INPUT #2, a: CLOSE #2
  IF a < 1 THEN
    COLOR 2: l = 0
    a$ = "!! WARNING !!  You haven't saved a game yet, any progress that you "
    a$ = a$ + "have made will be lost and you'll have to start back at the "
    a$ = a$ + "beginning when you return.": GOSUB Lp10: COLOR 3
  END IF
  PRINT "Are you sure you want to quit?"; : GOSUB AtFr1
  IF s$ <> "y" THEN GOTO Main
  CLS : CHDIR "..": RUN "EAMONDX"
  END
'---------------------------------------------------------------------------
' **** End of game routines ****
'
EndGame:
  COLOR 3: GOSUB Lp1: GOSUB Lp6
  IF die = 0 THEN
    PRINT "Leave this adventure?"; : GOSUB AtFr1
    IF s$ <> "y" THEN GOTO Main
  END IF
  a = 0: m = 0: w = 0: IF speed THEN m%(0, 2) = m%(0, 2) / 2
  IF die > 0 THEN GOTO Dead
  a$(22) = "rubies"
  IF ar > 1 AND ar <= na THEN
    a%(ar, 4) = 0: a = a%(ar, 5)
  END IF
  IF sh > 1 AND sh <= na THEN
    a%(sh, 4) = 0: m = 1
  END IF
  IF ac < 7 THEN ac = a + m
  FOR a = 1 TO na
     wp%(a) = 0
     IF a%(a, 4) = -999 THEN a%(a, 4) = -1
     IF a%(a, 4) > 1000 AND a%(a, 4) < 2001 THEN
       k = a%(a, 4) - 1000
       IF a%(k, 4) = -1 AND a%(a, 0) > 0 THEN a%(a, 4) = -1
     END IF
     IF a%(a, 4) = -1 AND (a%(a, 2) = 2 OR a%(a, 2) = 3) THEN
       w = w + 1: wp%(w) = a: a%(a, 4) = 0
     END IF
  NEXT
  IF w < 5 THEN GOTO EndGame1
  GOSUB Lp7: r = 35: GOSUB Effect: GOSUB Lp6
SellWep:
  GOSUB Lp7: PRINT "Your weapons are:": GOSUB Lp4
  s$ = "......................"
  FOR a = 1 TO w
     m = wp%(a)
     PRINT SPC(ABS(a < 10) + ABS(a < 100) + 5); a; ": ";
     a$ = LEFT$(a$(m), 20): PRINT a$;
     PRINT LEFT$(s$, 22 - LEN(a$)); "("; LTRIM$(RTRIM$(STR$(a%(m, 7))));
     PRINT "D"; LTRIM$(RTRIM$(STR$(a%(m, 8)))); ")": GOSUB Lp2
  NEXT: GOSUB Lp1
  INPUT "Enter the number of the weapon to sell:"; a$
  m = INT(VAL(a$)): IF m < 1 OR m > w THEN GOTO SellWep
  a%(wp%(m), 4) = -1: w = w - 1: IF m = w + 1 AND w > 4 THEN GOTO SellWep
  wp%(m) = wp%(w + 1): IF w > 4 THEN GOTO SellWep
EndGame1:
   GOSUB Lp7: r = 60: GOSUB Effect
  tp = 0
  FOR a = 1 TO naf
     IF a%(a, 4) = -1 THEN
       IF a%(a, 2) > 0 THEN a%(a, 1) = a%(a, 1) * (ch / 10)
       m = INT(a%(a, 1)): tp = tp + m
       PRINT UCASE$(LEFT$(a$(a), 1)); MID$(a$(a), 2);
       IF RIGHT$(a$(a), 1) = "s" THEN PRINT " are";
       IF RIGHT$(a$(a), 1) <> "s" THEN PRINT " is";
       PRINT " worth "; : s$ = LTRIM$(RTRIM$(STR$(m))) + " gold pieces."
       IF m < 1 THEN s$ = "nothing."
       PRINT s$: GOSUB Lp4
     END IF
  NEXT
  IF tp = 0 THEN PRINT "(You have nothing to sell)": GOSUB Lp4
  r = 36: GOSUB Effect: tp = tp + 2000
  IF loan > 0 THEN
    PRINT "You pay back your loan of "; loan; " gold pieces": GOSUB Lp4
    tp = tp - loan
  END IF
  PRINT "Your total comes to "; tp; " gold pieces.": GOSUB Lp4
  GOSUB Lp6: gold = INT(gold + tp): IF gold < 0 THEN gold = 0
  GOSUB Lp7: LOCATE 5
  IF m%(2, 5) = 31 AND m%(2, 11) = 3 THEN
    r = 106: GOSUB Effect: LOCATE 20: GOSUB Lp6
  END IF
  LOCATE 10, 10
  PRINT "Thank you for playing "; q$; "Adventure in Interzone"; q$; "."
  LOCATE 20: GOSUB Lp6
'
'  Kill player files and return to Main Hall
'
ExitRtn:
  CLOSE
  OPEN "GAMEDIR.DAT" FOR OUTPUT AS #1
  PRINT #1, -1
  FOR m = 1 TO 5
     PRINT #1, "(none)"
  NEXT: CLOSE
  FOR m = 1 TO 5
     a$ = "GAME" + LTRIM$(RTRIM$(STR$(m))) + ".SAV"
     OPEN a$ FOR OUTPUT AS #1: PRINT #1, 1: CLOSE : KILL a$
  NEXT
  KILL "NEW-MEAT"
'
' Re-set offend/don't offend flags
'
  KILL "OFFEND.DAT"
  OPEN "OFFEND.DAT" FOR OUTPUT AS #1
  FOR a = 1 TO 5: PRINT #1, 0: NEXT: CLOSE
'
' Update player record data
'
r = z.Status
z.CNAME = m$(0): z.Status = 1: z.A1 = m%(0, 1): z.a2 = m%(0, 2)
IF die = 1 THEN z.Status = 2
z.a3 = ch: z.SP1 = sp%(1): z.SP2 = sp%(2): z.SP3 = sp%(3): z.SP4 = sp%(4)
z.WA1 = wa%(1): z.WA2 = wa%(2): z.WA3 = wa%(3): z.WA4 = wa%(4): z.WA5 = wa%(5)
z.ae = ae: z.sex = sex: z.gold = gold: z.bank = bank: z.ac = ac
a = wp%(1): m = wp%(2): k = wp%(3): w = wp%(4)
z.WN1 = a$(a): z.WN2 = a$(m): z.WN3 = a$(k): z.WN4 = a$(w)
z.WCOMPLX1 = a%(a, 5): z.WCOMPLX2 = a%(m, 5): z.WCOMPLX3 = a%(k, 5)
z.WCOMPLX4 = a%(w, 5): z.WTYPE1 = a%(a, 6): z.WTYPE2 = a%(m, 6)
z.WTYPE3 = a%(k, 6): z.WTYPE4 = a%(w, 6): z.WDICE1 = a%(a, 7)
z.WDICE2 = a%(m, 7): z.WDICE3 = a%(k, 7): z.WDICE4 = a%(w, 7)
z.WSIDES1 = a%(a, 8): z.WSIDES2 = a%(m, 8): z.WSIDES3 = a%(k, 8)
z.WSIDES4 = a%(w, 8)
CLOSE
'
' Return to Test Bench
'
IF r < 1 THEN
  CHDIR "..": CHDIR "DD": RUN "DDMENU"
END IF
'
' Return to Main Hall
'
CHDIR "..": CHDIR "MAIN"
OPEN "PLAYERS.DAT" FOR RANDOM AS #1 LEN = 200
PUT #1, r, z
CLOSE
OPEN "PLAYER" FOR OUTPUT AS #2: WRITE #2, r: CLOSE
IF die <> 1 THEN RUN "MAINHALL"
CHDIR "..": RUN "EAMONDX"
'
' Player died
'
Dead:
  CLS
  PRINT "You have perished.  Now what?"
  PRINT "1. Restore a saved game"
  PRINT "2. Start over"
  PRINT "3. Give up, accept death": PRINT
  LINE INPUT "Your choice?"; a$: a = INT(VAL(a$))
  IF a < 1 OR a > 3 THEN GOTO Dead
  IF a = 3 THEN GOTO ExitRtn
  IF a = 2 THEN RUN
  GOTO GameRestore
'---------------------------------------------------------------------------
' Most-useful and main subroutines
'
' Read text from DESC file
'
Effect:
  r = r + 1200
DiskRead:
IF r < 401 THEN GET #10, r, DS
IF r > 400 AND r < 801 THEN GET #11, r - 400, DS
IF r > 800 AND r < 1201 THEN GET #12, r - 800, DS
IF r > 1200 THEN GET #13, r - 1200, DS
a$ = RTRIM$(DS.TEXT): GOSUB Lp0: GOTO Lp1

'
' Print a$ without wrap-around
'
Lp0:
  a$ = LTRIM$(a$)
  IF LEN(a$) <= 79 THEN PRINT a$:  GOTO Lp2
  FOR k = 79 TO 1 STEP -1
     IF MID$(a$, k, 1) = " " THEN
       PRINT LEFT$(a$, k - 1): a$ = RIGHT$(a$, LEN(a$) - k)
       GOSUB Lp2: k = 1
     END IF
  NEXT: GOTO Lp0
'
' Line counter & pause routines
'
Lp1:
  PRINT
Lp2:
  l = l + 1: GOTO Lp5
Lp3:
  l = l + 1
Lp4:
  l = l + 2: PRINT
Lp5:
  IF l < 20 THEN RETURN
Lp6:
  PRINT "[MORE]";
  zz$ = INKEY$
  DO
  LOOP UNTIL INKEY$ > ""
  LOCATE CSRLIN, 1: PRINT "      "; : LOCATE CSRLIN, 1: l = 0: RETURN
Lp7:
  CLS : l = 0: RETURN
Lp8:
  GOSUB Lp0: GOTO Main
Lp9:
  GOSUB Lp0: GOTO Pfoe
Lp10:
  GOSUB Lp0: GOTO Lp1
Lp11:
  GOSUB DiskRead: l = l - 1: LOCATE CSRLIN - 1, 1: RETURN
Lp12:
  GOSUB Lp4: GOTO Pfoe
'
Lp20:
  GOSUB Effect: GOTO Pfoe
'---------------------------------------------------------------------------
' Player input error messages
'
Err0:
  PRINT "Movement commands:"
  FOR c = 1 TO nd
     PRINT UCASE$(c$(c)),
  NEXT: PRINT UCASE$(c$(11)),
  COLOR 2: PRINT UCASE$(c$(12)): COLOR 12: PRINT
  PRINT "Artifact manipulation:"
  FOR c = 13 TO 26
     PRINT UCASE$(c$(c)),
  NEXT: PRINT : PRINT
  PRINT "Interactive:"
  FOR c = 27 TO 33
     PRINT UCASE$(c$(c)),
  NEXT: PRINT : PRINT
  PRINT "Miscelaneous:"
  FOR c = 34 TO nc
     PRINT UCASE$(c$(c)),
  NEXT: PRINT : PRINT
  l = 99: GOTO Main0
Err1:
  PRINT "That's not here.": GOTO Main0
Err2:
  PRINT "You must first open it.": GOTO Main0
Err3:
  a$ = "You can't " + c$(c) + " " + s$ + ".": GOTO Lp8
Err4:
  PRINT "Nobody here by that name!": GOTO Main0
'---------------------------------------------------------------------------
' Attack friend
'
AtFr:
  PRINT "Attack non-enemy?";
AtFr1:
  LINE INPUT "  (Y/N):"; s$: s$ = LTRIM$(RTRIM$(LCASE$(s$)))
  s$ = LEFT$(s$, 1)
  IF s$ = "" OR (s$ <> "y" AND s$ <> "n") THEN GOTO AtFr1
  l = 1: PRINT : RETURN
'---------------------------------------------------------------------------
' Synonym checker
'
Synonym:
  sl = LEN(s$): sy$ = "": sy = 0
  IF a%(49, 4) = ro OR a%(49, 4) = -1 THEN sy$ = "book": sy = 49
  IF ro = 3 AND a%(42, 4) = ro THEN sy$ = MID$(a$(42), 8): sy = 42
  GOSUB Synonym1: RETURN
Synonym1:
  IF LEFT$(sy$, sl) = s$ OR RIGHT$(sy$, sl) = s$ THEN s$ = a$(sy)
  RETURN
'---------------------------------------------------------------------------
'
' Set up enemy factor and see who folows player
'
EC: r3 = ro
EnemyCheck:
  t(1) = 0: t(2) = 0: t(3) = m%(0, 1)
  FOR xm = 1 TO nm
     IF m%(xm, 5) = r3 THEN
       IF xm = 36 AND m%(35, 5) = r3 AND r3 = 44 THEN GOTO EC0
       IF m%(xm, 14) = 1 THEN GOTO EC0
       IF xm = 2 AND (r3 = 52) THEN GOTO EC0
       IF m%(xm, 11) > 100 THEN
         rl = m%(xm, 11) - 100 + (ch - 10) * 2
         x = 1 + ABS(rl > RND * 100) + ABS(x = 2 AND rl > RND * 200)
         m%(xm, 11) = x
       END IF
       IF m%(xm, 11) = 3 OR xm = 1 THEN m%(xm, 5) = ro: GOTO EC0
       IF m%(xm, 11) = 1 THEN
         IF INT(RND * 100) + 1 <= m%(xm, 4) THEN m%(xm, 5) = ro
       END IF
     END IF
EC0:
  NEXT xm
Ec1:
  FOR xm = 1 TO nm
     IF m%(xm, 5) = ro THEN
       IF m%(xm, 11) > 3 THEN
         rl = m%(xm, 11) - 100 + (ch - 10) * 2
         k = 1 + ABS(rl > INT(RND * 100 + 1))
         k = k + ABS(k = 2 AND rl > INT(RND * 200 + 1))
         m%(xm, 11) = k
       END IF
       t(m%(xm, 11)) = t(m%(xm, 11)) + m%(xm, 1) * m%(xm, 3)
     END IF
  NEXT xm
  RETURN
'---------------------------------------------------------------------------
' Monster tries to get a weapon
'
GetWep:
  IF m%(of, 6) = -2 THEN RETURN
  w = 0: IF m%(of, 8) < 0 THEN w = ABS(m%(of, 8)) - 1
  IF w > 0 AND w <= na THEN
    IF a%(w, 0) = 1 AND (a%(w, 2) = 2 OR a%(w, 2) = 3) AND a%(w, 4) = ro THEN GOTO GetWep1
  END IF
  FOR x = 1 TO na
     IF a%(x, 4) = ro AND x <> 32 THEN
       IF (a%(x, 2) = 2 OR a%(x, 2) = 3) THEN
         IF a%(x, 0) = 1 AND a%(x, 7) * a%(x, 8) > a%(w, 7) * a%(w, 8) THEN w = x
       END IF
     END IF
  NEXT
GetWep1:
  IF w > 0 THEN
    a$ = m$(of) + " picks up " + a$(w) + ".": GOSUB Lp0
    a%(w, 4) = -of - 1: m%(of, 8) = w: GOTO Lp4
  END IF
  FOR x = 1 TO na
     IF a%(x, 4) = -of - 1 THEN
       IF (a%(x, 2) = 2 OR a%(x, 2) = 3) THEN
         IF a%(x, 7) * a%(x, 8) > a%(w, 7) * a%(w, 8) THEN w = x
       END IF
     END IF
  NEXT
  IF w > 0 THEN
    a$ = m$(of) + " readies " + a$(w) + ".": GOSUB Lp0
    m%(of, 8) = w: GOTO Lp4
  END IF
  IF m%(of, 6) = -1 AND m9 = 1 THEN GOTO Battle0
  RETURN
'---------------------------------------------------------------------------
'  Combat routine
'
Battle:
  IF of = 11 THEN
    a$ = m$(of) + " BLASTS " + m$(df) + "!": GOSUB Lp0
    FOR a = 600 TO 100 STEP -20: SOUND a, 1: NEXT
    rl = 10: GOSUB RollDice2
    IF rl > 8 THEN PRINT " === A miss!": GOTO Lp4
    COLOR 2: PRINT " *** ZAP!  Direct hit! ***": COLOR 3: GOSUB Lp2
    s = 5: d = 2: a = 0: GOTO Damage0
  END IF
  IF m%(of, 6) = -2 THEN RETURN
  w2 = 0: IF m%(0, 8) > 1 AND m%(0, 8) >= na THEN w2 = a%(m%(0, 8), 6)
  hi = 0: w = m%(of, 8)
  IF w < 0 THEN GOTO GetWep
Battle0:
' Compute players armor factor
'
  IF w = 32 THEN
    COLOR 2: PRINT "The "; a$(w); " explodes in "; m$(of); "'s hands!"
    COLOR 3: GOSUB Lp2: df = of: d2 = 0: m%(of, 13) = m%(of, 1) - 5
    m%(of, 8) = -1: a%(w, 4) = 0: GOTO Mstatus
  END IF
  a3 = 0: IF ar > 1 AND ar <= na THEN a3 = a%(ar, 5)
  IF sh > 1 AND sh <= na THEN a3 = a3 + 1
  IF a2 > 7 THEN a3 = 7
  ea = 0: IF ae < a3 * a3 THEN ea = ae - ac * ac
'
'  Compute odds to hit
'
  wm = 50 + 2 * (m%(of, 2) - m%(df, 2) - m%(of, 7) + m%(df, 7))
  IF w > 0 THEN wm = wm + a%(w, 5) / 2
  IF of = 0 THEN wm = wm + wa%(w2) / 4 + ea
  a = a%(w, 6) * ABS(w > 0)
  a$ = m$(of) + " " + bv$(a, INT(RND * 3)) + " at " + m$(df) + "..."
  GOSUB Lp0: GOSUB RollDice
  IF (rl < 5 OR rl < wm) AND rl < 97 THEN
    hi = 1: GOTO Battle1
  END IF
  a2 = 0
  IF m%(df, 8) > 0 THEN a2 = a%(m%(df, 8), 6)
  IF of = 26 OR rl < 97 OR w = 0 THEN
    PRINT " --- "; rb$(a2, INT(RND * 2)); "!": GOTO Lp4
  END IF
  PRINT "...A fumble!": GOSUB Lp2: r = INT(RND * 100 + 1)
  IF r < 41 THEN
    PRINT "    Recovered.": GOTO Lp4
  END IF
  IF r < 81 THEN
    a$ = m$(of) + " drops " + a$(w) + "!": GOSUB Lp0
    wt = wt - (ABS(of = 0) * a%(w, 3)): a%(w, 4) = ro
    m%(of, 8) = -w - 1:  GOTO Lp1
  END IF
  IF a%(w, 2) = 3 THEN
    a$ = "Sparks fly from " + a$(w) + "!": GOTO Lp9
  END IF
  IF r > 95 THEN
    PRINT " Weapon hits user!": GOSUB Lp4: df = of
    ON ABS(r = 100) + 1 GOTO Battle2, Battle3
  END IF
  IF r < 91 THEN
    a%(w, 8) = a%(w, 8) - 1
    IF a%(w, 8) > 0 THEN
      PRINT " Weapon damaged!": GOTO Lp4
    END IF
  END IF
  PRINT " Weapon broken!": wt = wt - (ABS(of = 0) * a%(w, 3))
  a%(w, 4) = 0: m%(of, 8) = -1
  IF RND > .5 THEN GOTO Lp4
  PRINT " Broken weapon hits user!": GOSUB Lp4: df = of
  ON ABS(r = 100) + 1 GOTO Battle2, Battle3
Battle1:
  IF of = 0 THEN
    up = ABS(INT(RND * 100) + 1 > wm + wa%(w2))
    IF INT(RND * 100) + 1 < wa%(w2) THEN
      IF ABS(ea) > INT(RND * 10) + 1 AND ae < a3 * a3 AND ae < 65 THEN
        ae = ae + 2
        s$ = MID$("'s'", ABS(LCASE$(RIGHT$(m$(0), 1)) = "s") * 2 + 1, 2)
        a$ = m$(0) + s$ + " armor expertise just increased!": GOSUB Lp10
      END IF
    END IF
  END IF
Battle2:
  d = m%(of, 9): s = m%(of, 10)
  IF w > 0 THEN
    d = a%(w, 7): s = a%(w, 8)
  END IF
  a = 1: PRINT MID$(" ***  +++ ", ABS((df > 0)) * 5 + 1, 5);
  IF rl > 5 THEN
    PRINT "A hit!": GOSUB Lp2: GOTO Damage0
  END IF
Battle3:
  PRINT "Well struck!": GOSUB Lp2: r2 = INT(RND * 100) + 1
  IF r2 < 51 THEN
    a = 0: GOTO Damage0
  END IF
  rl = 1.5
  IF r2 > 85 THEN
    rl = 2: GOTO Damage0
  END IF
  IF r2 > 95 THEN
    rl = 3: GOTO Damage0
  END IF
  IF r2 = 100 THEN rl = m%(df, 1)
  s = rl * s
Damage0:
  d2 = 0
  IF of = 26 AND w = 24 THEN d = 1: s = 10
  FOR k = 1 TO d
     d2 = d2 + INT(RND * s) + 1
  NEXT
  d2 = INT(d2 - a * m%(df, 7))
  IF d2 < 1 AND m%(df, 7) = 0 THEN
    PRINT "  Blow turned!": GOTO Lp4
  END IF
Damage1:
  IF d2 < 1 THEN
    PRINT "  Armor absorbs damage!": GOTO Lp4
  END IF
'---------------------------------------------------------------------------
' Add damage/report monster's health
'
Mstatus:
  a$ = ""
  IF m%(df, 3) > 1 THEN a$ = "One "
  a$ = m$(df) + " is "
  m%(df, 13) = m%(df, 13) + d2
  IF m%(df, 13) >= m%(df, 1) THEN GOTO Mdead
  IF m%(df, 13) = 0 THEN GOTO Ms1
  xm% = m%(df, 13) * 5 / m%(df, 1) + 1
  ON xm% GOTO Ms2, Ms3, Ms4, Ms5, Ms6, Ms6
  PRINT xm%: END
Ms1:
  a$ = a$ + "in perfect health.": GOTO Lp10
Ms2:
  a$ = a$ + "OK.": GOTO Lp10
Ms3:
  a$ = a$ + "hurt.": GOTO Lp10
Ms4:
  a$ = a$ + "badly hurt.": GOTO Lp10
Ms5:
  a$ = a$ + "gravely injured.": GOTO Lp10
Ms6:
  a$ = a$ + "dying.": GOTO Lp10
'---------------------------------------------------------------------------
' Monster dies
'
Mdead:
  s$ = "dead!": IF df = 26 THEN s$ = "severely wounded!"
  a$ = a$ + s$: GOSUB Lp10
  IF m%(df, 3) > 1 THEN
    m%(df, 3) = m%(df, 3) - 1: m%(df, 13) = 0: GOTO Mdead2
  END IF
  IF df = 0 THEN die = 1: GOTO Lp10
  m%(df, 8) = -1 * ABS(m%(df, 8) <> 0): m%(df, 5) = 14: IF ro = 14 THEN m%(df, 5) = 17
  m%(df, 3) = m%(df, 12): m%(df, 13) = INT(m%(df, 1) / 3)
  FOR a2 = 1 TO na
     IF a%(a2, 4) = -df - 1 OR a%(a2, 4) = -df - 1000 THEN a%(a2, 4) = ro
  NEXT a2
Mdead0:
'
' Add special effects of a monsters death here
'
  r = m%(df, 15): IF r = 17 AND ro <> 1 THEN r = 0
  IF r > 0 THEN COLOR 2: GOSUB Effect: COLOR 3
  IF df = 2 AND (ro < 7 OR ro > 38) THEN d%(9) = 1
  IF db > 0 THEN a%(df + db - 1, 4) = ro
  IF df = 17 THEN
    m%(df, 11) = 2: m%(df, 5) = ro: r3 = ro: GOTO EnemyCheck
  END IF
  IF (ro < 7 OR ro > 38) AND ro <> 53 AND of = 0 THEN
    IF df <> 2 AND df <> 6 AND df <> 9 AND df <> 10 THEN
      IF df <> 39 AND df <> 37 THEN
        r = 83: GOSUB Effect: die = 1
      END IF
    END IF
  END IF
Mdead2:
  w = m%(df, 11): t(w) = t(w) - m%(df, 1)
  RETURN
'---------------------------------------------------------------------------
' Was player's spell successful?
'
SpellCast:
  suc = 0: GOSUB RollDice: rl = rl * ABS(sp%(s) > 0)
  IF (rl < sa%(s) OR rl < 5) AND rl < 100 AND rl > 0 THEN suc = 1
  IF rl = 100 THEN
    a$ = "Spell backlash!!  Your ability to cast the " + c$(c) + " spell "
    a$ = a$ + "temporarily diminishes!": GOSUB Lp0: sa%(s) = 6
  END IF
  IF suc = 0 THEN
    PRINT "Nothing happened.": GOSUB Lp2
  END IF
  IF suc = 1 THEN
    GOSUB RollDice
    IF rl > sp%(s) THEN
      sp%(s) = sp%(s) + 2: sa%(s) = sa%(s) + 2
      a$ = m$(0) + MID$("'s'", (LCASE$(RIGHT$(m$(0), 1)) = "s") * 2 + 1, 2)
      a$ = a$ + " ability to cast " + c$(c) + " just increased by 2!"
      GOSUB Lp0: GOSUB Lp1
    END IF
    IF sa%(s) > 9 THEN sa%(s) = sa%(s) / 2
  END IF
  RETURN
'---------------------------------------------------------------------------
' Get a random roll between 1 and RL
'
RollDice:
  rl = 100
RollDice2:
  rl = INT(RND * rl + 1)
  RETURN
'---------------------------------------------------------------------------
' Get an item before doing something with it (Ready/Wear/Etc.)
'
ItemTake:
  IF a%(a, 4) = -1 THEN RETURN
  PRINT "(Taking it first.)"
  IF (a%(a, 0) = 5 OR (a = 32 OR a = 33 OR a = 38) AND a%(37, 6) = 0) AND m%(37, 5) = ro THEN
    PRINT "Big Bob won't let you.": GOTO Lp4
  END IF
  IF a = 42 AND m%(32, 5) = ro THEN
    PRINT "It's not yours to take.": GOTO Lp4
  END IF
  IF a > 21 AND a < 25 AND m%(26, 5) = ro AND m%(26, 11) > 1 THEN
    m%(26, 11) = 1: GOSUB Lp1: r = 88: GOSUB Effect: GOTO EnemyCheck
  END IF
  IF wt + a%(a, 3) > m%(0, 1) * 10 OR a%(a, 3) = -999 OR a%(a, 3) > 900 THEN
    PRINT "It's too heavy.": GOTO Lp4
  END IF
  a%(a, 4) = -1: wt = wt + a%(a, 3): RETURN
'---------------------------------------------------------------------------
' Monster search routine
'
Msearch:
  wh = ro: ha = wh
Msearch0:
  F = 0: sl = LEN(s$): m = 0
  FOR x = 1 TO nm
     IF s$ = LCASE$(m$(x)) THEN
       IF m%(x, 5) = wh OR m%(x, 5) = ha THEN
         m = x: F = F + 1:  x = nm:  GOTO Msearch1
       END IF
     END IF
     IF s$ = LEFT$(LCASE$(m$(x)), sl) OR s$ = RIGHT$(LCASE$(m$(x)), sl) THEN
       IF m%(x, 5) = wh OR m%(x, 5) = ha THEN
         m = x: F = F + 1
       END IF
     END IF
Msearch1:
  NEXT
  IF F = 0 THEN
    IF RIGHT$(s$, 1) = "s" AND sl > 1 THEN
      s$ = LEFT$(s$, sl - 1): GOTO Msearch0
    END IF
  END IF
  RETURN
'---------------------------------------------------------------------------
' Artifact search routine
'
Asearch:
  ha = -1: wh = ha: em = ha: GOTO Asearch2
Asearch0:
  ha = -1
Asearch1:
  wh = ro: em = ro + 2000
Asearch2:
  GOSUB Synonym: F = 0
  FOR x = 1 TO na
     IF s$ = LCASE$(a$(x)) THEN
       a2 = a%(x, 4)
       IF a2 = ha OR a2 = wh OR a2 = em THEN
         a = x: F = F + 1: a = x: x = na: F = 1: GOTO Asearch3
       END IF
     END IF
     IF s$ = LEFT$(LCASE$(a$(x)), sl) OR s$ = RIGHT$(LCASE$(a$(x)), sl) THEN
       a2 = a%(x, 4)
       IF a2 = ha OR a2 = wh OR a2 = em THEN
         a = x: F = F + 1
       END IF
     END IF
Asearch3:
  NEXT
  IF F > 1 THEN
    F = 0: a$ = "(Which " + q$ + s$ + q$ + " do you mean?)": GOSUB Lp0
  END IF
  RETURN
'---------------------------------------------------------------------------
' Check/get s$
'
CheckSub:
  IF s$ <> "" THEN RETURN
CheckSub1:
  PRINT UCASE$(LEFT$(c$(c), 1)); MID$(c$(c), 2);
  LINE INPUT " who or what?", s$: s$ = LCASE$(LTRIM$(RTRIM$(s$)))
  PRINT : l = 1: GOTO CheckSub
'---------------------------------------------------------------------------
' Check/get s2$
'
CheckSub2:
  IF s2$ <> "" THEN RETURN
  PRINT a$; : LINE INPUT "?"; s2$: s2$ = LTRIM$(RTRIM$(LCASE$(s2$)))
  l = 1: PRINT : GOTO CheckSub2
END SUB

