'     THE WONDERFUL WORLD OF EAMON DELUXE (v2)
'           BY FRANK BLACK 1997-1999
'
'   A COMPUTERIZED FANTASY ROLE-PLAYING SYSTEM
' BASED UPON THE APPLE II VERSION BY DONALD BROWN,
'    JOHN NELSON, TOM ZUCHOWSKI, & FRANK BLACK
'
'              BASE DUNGEON PROGRAM v4.1a
'
' The Devil's Tomb                           Last update 2 JUN 1999
' By Jim Jacobson -- Expanded by Frank Black
'
'  d%(1) Trezore spell power level  d%(10) Gold Warrior's 'memory'
'  d%(2) Zombie counter             d%(11) Black Warrior's 'memory'
'  d%(3) Door counter               d%(12) Gold new Warrior's 'memory'
'  d%(4) Wrestling match flag       d%(13) Black new Warrior's 'memory'
'
' wheel$( 1-5) Wheel designs  wheel(x, 1) ASCII value of design
' wheel$(6-10) Wheel results  wheel(x, 2) Row to LOCATE at
'                             wheel(x, 3) Column to LOCATE at (left)
' gw$(3) Gold War's comments  wheel(x, 4) Column to LOCATE at (right)
'
DECLARE SUB Main ()
TYPE DESC
  TEXT AS STRING * 253
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
  ARTNAME 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
'
TYPE visitors
   pname AS STRING * 40: psex AS STRING * 3: v0 AS INTEGER: v1 AS INTEGER
   v2 AS INTEGER: v3 AS INTEGER: v4 AS INTEGER: v5 AS INTEGER: v6 AS INTEGER
   v7 AS INTEGER: v8 AS INTEGER: v9 AS INTEGER: v10 AS INTEGER: v11 AS INTEGER
   v12 AS INTEGER: v13 AS INTEGER: v14 AS INTEGER: v15 AS INTEGER
   v16 AS INTEGER: v17 AS INTEGER: v18 AS INTEGER: v19 AS INTEGER
   v20 AS INTEGER: v21 AS INTEGER: v22 AS INTEGER: v23 AS INTEGER
   v24 AS INTEGER: v25 AS INTEGER: v26 AS INTEGER
END TYPE
DIM vv AS visitors
'
DIM SHARED a, a$, a2, ac, ae, aname$, ar, bank, C, ch, cz$, d, D2, db, df, die
DIM SHARED ea, em, f, gold, ha, hit, k, l, ls, lt, m, mc, mr%, na, naf, nc
DIM SHARED nd, ne, nh, nl, nm, nr, nw, nx, odds, of, q$, r, r2, r3, rec, rl
DIM SHARED ro, s, s$, s2$, sex, sh, SL, Speed, suc, sy, sy$, ta, tp, up
DIM SHARED v$, ver, w, w2, wh, wt, x, xm
DIM SHARED dly, CC1, CC2, CC3, adj1, adj2, adj3, adj4
'
'  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
nr = 47: naf = 59: nm = 18: ne = 10: na = naf + 6
adj1 = 116: adj2 = 107: adj3 = 38: adj4 = 33
'
OPEN "HINTDIR.DAT" FOR INPUT AS #1
INPUT #1, nh: DIM SHARED h$(nh), h%(nh, 2)
FOR r = 1 TO nh
   LINE INPUT #1, h$(r): INPUT #1, h%(r, 1), h%(r, 2)
NEXT: CLOSE
'
READ nc
DIM SHARED a$(na), a%(na, 8), bv$(5, 2), C$(nc), d%(200), m$(nm), m%(nm, 15)
DIM SHARED r%(nr, 11), r$(nr), rb$(5, 1), sa%(4), sa$(4), sex$(2), sp%(4)
DIM SHARED sp$(4), sm$(3), t(4), wa%(5), wp%(na), wp$(5), gm$(5)
DIM SHARED Wheel$(10), Wheel(5, 4), gw$(3)
'---------------------------------------------------------------------------
'  Input data from files
'
Init:
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 + adj1, 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 + adj2, art
   a$(a) = RTRIM$(art.ARTNAME): 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 + adj3, 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)
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 + 4
FOR a = naf + 1 TO na
   a$ = UCASE$(LEFT$(a$(a), 4))
   IF a$ <> "NONE" AND a$ <> "" THEN
     m = ABS((a%(a, 7) * a%(a, 8) > 25))
     a%(a, 2) = 2 + m: a%(a, 1) = 20 * (m + 1)
     a%(a, 3) = 2: wt = wt + 2: : a%(a, 4) = -1
   END IF
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)
sex$(0) = "Male": sex$(1) = "Female"

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
FOR a = naf + 1 TO na: a%(a, 0) = 1: NEXT
IF nd = 6 THEN FOR C = 7 TO 10: C$(C) = "": NEXT
'
' Initialize Wheel of Fortune & Gold Warrior data
'
FOR a = 1 TO 5
   READ m: a$ = CHR$(m): Wheel$(a) = a$ + a$ + a$ + a$
   FOR m = 1 TO 3: READ Wheel(a, m): NEXT
   READ Wheel$(a + 5)
NEXT
FOR a = 1 TO 3: READ gw$(a): NEXT

'
'  Load 'memories'
'
OPEN "visitors.dat" FOR RANDOM AS #1 LEN = 97
GET #1, 1, vv
r = 0: m = vv.v26: IF m = 0 THEN GOTO Vl
FOR a = 1 TO m
   GET #1, a, vv: a$ = LCASE$(LTRIM$(RTRIM$(vv.pname)))
   IF a$ = LCASE$(m$(0)) THEN r = a: a = m
NEXT
IF r = 0 THEN GOTO Vl
GET #1, r, vv
d%(10) = vv.v6: d%(11) = vv.v7

Vl:
CLOSE
OPEN "ROOMS.DSC" FOR RANDOM AS #2 LEN = 255
OPEN "ARTIFACT.DSC" FOR RANDOM AS #3 LEN = 255
OPEN "MONSTERS.DSC" FOR RANDOM AS #4 LEN = 255
OPEN "EFFECT.DSC" FOR RANDOM AS #5 LEN = 255
db = 39
IF d%(10) > 2 THEN m%(17, 5) = 2
IF d%(11) > 0 THEN m%(18, 5) = 18
'
' Ranomize the RND seed
'
CLS : PRINT "(Base dungeon prog. v4.1a)": LOCATE 12: COLOR 2
PRINT "Welcome to the Eamon Deluxe fantasy gaming system!"
PRINT : PRINT SPC(13); "Hit any key to begin.": a$ = INKEY$
DO
  a = RND
LOOP UNTIL INKEY$ <> ""
CLS : LOCATE 24
'----------------------------------------------------------------------------
' Start the game
'
CALL Main
'
'----------------------------------------------------------------------------
' Game returns here when finished
CLOSE
OPEN "visitors.dat" FOR RANDOM AS #1 LEN = 97
GET #1, 1, vv
r = 0: m = vv.v26: IF m = 0 THEN r = 1: m = 1: GOTO Visitor
FOR a = 1 TO m
   GET #1, a, vv: a$ = LCASE$(LTRIM$(RTRIM$(vv.pname)))
   IF a$ = LCASE$(m$(0)) THEN r = a: a = m
NEXT
IF r = 0 THEN m = m + 1: r = m
'
Visitor:
GET #1, r, vv
vv.pname = m$(0): vv.psex = "he": IF sex = 1 THEN vv.psex = "she"
vv.v8 = d%(12): vv.v9 = d%(13): vv.v23 = vv.v23 + 1
PUT #1, r, vv
GET #1, 1, vv: vv.v26 = m: PUT #1, 1, vv
'
'  Delete 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"
'
' 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.BAS"
'
' 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.BAS"
CHDIR "..": RUN "STARTUP.BAS"
'
DATA 42,north,south,east,west,up,down,ne,nw,se,sw,flee,close,drink,drop,eat
DATA examine,get,light,open,put,read,ready,remove,use,wear,attack,blast,free
DATA give,heal,request,smile,inventory,look,say,speed,power,status,hints,save
DATA 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,Missed,Parried,Missed,Missed,Missed,Parried,Missed,Parried,Missed
DATA Parried,Missed
'
DATA growl,ignore,smile
'
DATA axe,missile weapon,club,spear,sword
'
DATA 156,5,37,37,-- DOUBLE --
DATA 157,8,49,27,>>> LOSE <<<
DATA 234,11,57,17,*** WIN ****
DATA 228,14,49,27," D E A T H  "
DATA 156,17,37,37,-- DOUBLE --
'
DATA Don't make me laugh!,"Bring it on, wimp!",I'll handle this!

SUB Main

GOTO Move2
'----------------------------------------------------------------------------
' Main Loop
'
Main0:
GOSUB Lp4

Main:
IF die = 1 THEN GOTO Endgame
GOSUB Lp1: IF ls = 0 THEN GOTO Main2A
IF a%(ls, 5) = -1 THEN GOTO Main2A: COLOR 2
a%(ls, 5) = a%(ls, 5) - 1: m = a%(ls, 5)
IF m = 0 THEN
  PRINT "Your "; a$(ls); " has gone out!": COLOR 12
  ls = 0: lt = nl: GOTO Main0
END IF

Main1A:
IF m < 10 THEN
  PRINT "Your "; a$(ls); " is almost out!": GOSUB Lp4: GOTO Main2A
END IF

Main1B:
IF m < 20 THEN
  PRINT "Your "; a$(ls); " grows dim!": GOSUB Lp4
END IF

Main2A:
COLOR 12
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
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
    PRINT "It's too dark to see.": GOSUB Lp4: GOTO Com1
END IF
'
' Give room name and description
'
Main3B:
PRINT r$(ro): GOSUB Lp4
IF r%(ro, 0) = 0 THEN
  r%(ro, 0) = 1: r = ro: GOSUB DiskRead1
END IF
IF ro = 44 THEN die = 1: GOTO Endgame
'
' 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: GOSUB DiskRead3: 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 = 1: GOTO Main5B
   END IF
   IF a%(a, 0) = 0 THEN
     IF m2 = 0 THEN GOSUB Lp1
     a%(a, 0) = 1: r = a: GOSUB DiskRead2: 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
'
' Get command
'
Com0:
GOSUB Lp1
IF m%(17, 5) = 2 AND a%(1, 7) = 1 THEN
  d%(3) = d%(3) + 1: IF d%(3) < 3 THEN GOTO Com1
  a%(1, 6) = 0: a%(1, 7) = 0: r = 8: COLOR 2: GOSUB Effect: COLOR 12
END IF
IF m%(17, 5) = ro AND m%(18, 5) = ro AND d%(4) = 0 THEN
  d%(4) = 1: r = 9: COLOR 2: GOSUB Effect: COLOR 12: GOTO Com1
END IF
IF t(1) > 1 AND m%(17, 5) = ro THEN
  rl = 3: GOSUB RollDice2: COLOR 2
  PRINT m$(17); " says, "; q$; gw$(rl); q$: COLOR 12: GOSUB Lp4
END IF
Com1:
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$ = ""
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
IF v$ = "" THEN v$ = a$: GOTO Com2
'
FOR a = 1 TO LEN(s$)
   zz$ = MID$(s$, a, 3)
   IF zz$ = "to " OR zz$ = "on " OR zz$ = "in " THEN
     s2$ = LTRIM$(RTRIM$(MID$(s$, a + 3)))
     s$ = LTRIM$(RTRIM$(LEFT$(s$, a - 1)))
   END IF
NEXT: IF s2$ <> "" THEN GOTO Com2
FOR a = 1 TO LEN(s$)
   zz$ = MID$(s$, a, 5)
   IF zz$ = "from " OR zz$ = "with " THEN
     s2$ = LTRIM$(RTRIM$(MID$(s$, a + 5)))
     s$ = LTRIM$(RTRIM$(LEFT$(s$, a - 1)))
   END IF
NEXT
'
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
IF C = 0 THEN GOTO Err0
COLOR 3
Com3:
ON C GOTO Move, Move, Move, Move, Move, Move, Move, Move, Move, Move, Flee
ON C - 11 GOTO ItemClose, Drink, Drop, Drink, Examine, ItemGet, Light, ItemOpen
ON C - 19 GOTO ItemPut, ItemRead, Ready, Remove, Use, Wear
ON C - 25 GOTO Attack, Blast, Free, Give, Heal, Request, Smile
ON C - 32 GOTO Inventory, Look, Say, Speed, Power, Status, Hints
ON C - 39 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
'
IF mr% = m%(m, 3) THEN
  GOSUB Flee1: m%(m, 5) = r2: GOSUB EnemyCheck: GOTO Pfoe2A
END IF
m%(m, 3) = m%(m, 3) - mr%: r3 = ro: GOSUB EnemyCheck
'
'  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) > 1 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: 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: 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
IF t(1) = 0 THEN
  FOR of = 1 TO nm
     IF m%(of, 5) = ro AND m%(of, 8) < 0 THEN GOSUB GetWep
  NEXT
END IF
IF m%(11, 5) = ro AND m%(11, 11) = 3 THEN
  d%(2) = d%(2) + 1: IF d%(2) < 40 THEN GOTO Main
  m%(11, 11) = 1: GOSUB EnemyCheck: COLOR 2: r = 7: GOSUB Effect: COLOR 3
END IF
GOTO Main
'---------------------------------------------------------------------------
' **** Movement commands ****
'
' **** Directions ****
'
Move:
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
'
' Add special (negative) moves here
'
IF r2 = -999 THEN
  PRINT "You successfully ride off into the sunset.": DI = 0: GOTO Endgame
END IF
PRINT "You can't go that way!": GOTO Main0
'
' Doors/Gates
'
Move1:
a = r2 - 1000
IF a%(a, 4) <> ro AND a%(a, 4) <> ro + 2000 THEN r2 = 0: GOTO MoveCheck
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 r2 = 0: GOTO MoveCheck
PRINT "The "; a$(a); " blocks the way!": GOTO Main0
'
' Go to another room
'
Move2:
IF ls > 0 AND ls <= na THEN IF a%(ls, 4) <> -1 THEN ls = 0
r3 = ro: ro = r2: GOSUB MoveMons: GOSUB EnemyCheck
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
IF nl > 0 AND ls > 0 THEN
  IF a%(ls, 5) = -1 THEN GOTO Main
  PRINT "It's not dark here.  Extinguish the "; a$(ls); "?";
  GOSUB Af1: IF s$ = "y" THEN ls = 0
END IF
GOTO Main
'
' **** Flee command ****
'
Flee:
IF t(1) = 0 THEN PRINT "Calm down.": GOTO Main0
IF nx = 0 THEN PRINT "There's no place to run!": GOTO Main0
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
'---------------------------------------------------------------------------
'  Artifact manipulation commands
'
' **** Close command ****
'
ItemClose:
GOSUB CheckSub: GOSUB Asearch0: IF f = 0 THEN GOTO Err1
m = a%(a, 2): k = 6 + ABS(m = 8): w = 1 - ABS(m = 8)
IF m <> 4 AND m <> 8 THEN PRINT "You can't close it.": GOTO Main0
IF a%(a, k) <> w THEN PRINT "It's not open.": GOTO Main0
GOSUB Pu0: PRINT a$; "closed.": a%(a, k) = 0 + ABS(m = 8): GOTO Lp12
'
' **** Drink & Eat commands ****
'
Drink:
GOSUB CheckSub: GOSUB Asearch0: IF f = 0 THEN GOTO Err3
m = a%(a, 2): IF m <> 6 AND m <> 9 THEN GOTO Err3
IF a%(a, 7) = 0 THEN GOTO Err2
IF a%(a, 6) < 1 THEN PRINT "There's none left.": GOTO Lp12
'
a%(a, 6) = a%(a, 6) - 1
IF a%(a, 6) = 0 AND m = 9 THEN
  PRINT "You eat the last one.": GOSUB Lp4: GOSUB Wtrem: a%(a, 4) = 0
END IF
IF a = 21 THEN PRINT "Yumm!": GOTO Lp12
'
m%(0, 13) = m%(0, 13) - a%(a, 5): IF m%(0, 13) < 0 THEN m%(0, 13) = 0
PRINT "You feel "; MID$("betterworse", ABS(a%(a, 5) < 0) * 6 + 1, 6); "!"
GOSUB Lp4: df = 0: D2 = 0: GOSUB Mstatus: GOTO Pfoe
'
'  **** Drop command ****
'
Drop:
IF lt = 0 THEN GOTO Main
GOSUB CheckSub: GOSUB Asearch: IF s$ = "all" THEN GOTO Drop1
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: wt = 0: m%(0, 8) = -1
FOR a = 1 TO na
   IF a%(a, 4) = -999 THEN wt = wt + a%(a, 3)
NEXT
GOSUB Lp4: GOTO Pfoe
'
' Add special effects of drop here
'
Drop2:
wt = wt - a%(a, 3): a%(a, 4) = ro: IF a = m%(0, 8) THEN m%(0, 8) = -1
GOSUB Pu0: PRINT a$; "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
  ha = -999: wh = ha: em = ha: GOSUB Asearch2: IF f = 0 THEN GOTO Examine1
END IF
'
' ** Examine artifact **
'
IF a%(a, 4) = em AND em <> -999 THEN a%(a, 4) = ro
IF a%(a, 2) = 8 THEN a%(a, 8) = 0
Examine0:
IF a > naf THEN PRINT "This is your "; a$(a); ".": GOTO Lp12
IF a%(a, 2) = 12 THEN GOSUB ItemGet3: GOTO Main
r = a: GOSUB DiskRead2: a%(a, 0) = 1
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 PRINT "You see nothing special.": GOTO Lp12
r = m: GOSUB DiskRead3: df = m: D2 = 0
IF m%(m, 3) > 1 AND m%(m, 13) = 0 THEN a$ = "They are ": GOSUB Ms1: GOTO Pfoe
GOSUB Mstatus: GOTO Pfoe
'
'  **** The Get command ****
'
ItemGet:
IF lt = 0 THEN GOTO Main
GOSUB CheckSub: IF s$ = "all" THEN GOTO ItemGet2
ha = ro: wh = ha: em = ro + 2000: GOSUB Asearch2
IF f = 0 THEN s$ = "that": GOTO Err3
IF db > 0 AND a >= db AND a <= naf THEN
  PRINT "Dead bodies are best if left alone.": GOTO Main0
END IF
GOSUB ItemGet3: GOSUB Lp4: GOTO Pfoe
'
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%(a, 3) > 900 OR a%(a, 3) = -999 THEN GOTO ItemGet2A
     GOSUB ItemGet3
   END IF
ItemGet2A:
NEXT: GOTO Pfoe
'
ItemGet3:
a2 = a%(a, 2)
IF a2 = 12 THEN
  GOSUB Pu0: PRINT a$; "is alive!": GOSUB Lp4
  IF a%(a, 6) > 0 THEN
    FOR x = 1 TO a%(a, 7): r = a%(a, 6) + x - 1: GOSUB Effect: 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 Lp4
IF a%(a, 3) = -999 THEN PRINT "You can't get that.": GOTO Lp4
IF a = 6 THEN
  COLOR 2: PRINT "The apple explodes as you touch it!": COLOR 3: GOSUB Lp4
  a%(a, 4) = 0: d = 2: s = 4: a = 0: df = 0: GOTO Damage0
END IF
GOSUB Pu0: PRINT a$;
'
'
IF wt + a%(a, 3) > 10 * m%(0, 1) THEN PRINT "is too heavy.": GOTO Lp2
IF a2 = 10 THEN PRINT "must be freed.": GOTO Lp2
'
PRINT "taken.": a%(a, 4) = -1: wt = wt + a%(a, 3)
IF a = 3 THEN
  GOSUB Lp4: COLOR 2: r = 2: GOSUB Effect: COLOR 3
  d = 1: s = 6: a = 0: df = 0: GOSUB Damage0
END IF
IF m%(0, 8) < 1 AND (a2 = 2 OR a2 = 3) AND a > 3 THEN
   m%(0, 8) = a: GOSUB Lp1: PRINT a$(a); " readied.": GOTO Lp4
END IF
GOTO Lp2
'
' **** Light command ****
'
Light:
GOSUB CheckSub: GOSUB Asearch0: IF f = 0 THEN GOTO Err1
IF a%(a, 2) <> 5 THEN GOTO Err3
IF a%(a, 5) = 0 THEN PRINT "It won't light.": GOTO Lp12
IF a <> ls THEN lt = 1: ls = a: PRINT "You've lit the "; a$(a); ".": GOTO Lp12
IF a = ls THEN PRINT "Extinguish the "; a$(a); "?": GOSUB Af1
IF s$ = "y" THEN ls = 0: lt = nl
GOTO Pfoe
'
' **** Open command ****
'
ItemOpen:
IF lt = 0 THEN GOTO Main
GOSUB CheckSub: GOSUB Asearch0: IF f = 0 THEN GOTO Err1
m = a%(a, 2): IF a%(a, 4) = em THEN a%(a, 4) = ro
IF a = 17 THEN PRINT "Try READing it.": GOTO Main0
IF a = 11 THEN
 COLOR 2: r = 1: GOSUB Effect: COLOR 3: a = 0: d = 1: s = 6: df = 0
 GOSUB Damage0: GOTO Pfoe
END IF
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 GOTO Err3
'
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
'
' ** Open container **
'
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
IF a%(a, 6) > 1 THEN PRINT "It's locked.": GOTO Lp12
'
a%(a, 5) = 0: a%(a, 6) = 1
GOSUB Pu0: PRINT a$; "opened.": GOSUB Lp4: GOSUB Inv4: GOTO Pfoe
'
' ** Open doors/gates **
'
DoorOpen:
k = a%(a, 6)
IF k = 0 AND 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
  a$ = "You open it with the " + a$(k) + ".": GOTO DoorOpen1
END IF
'
IF a%(a, 7) > 1 THEN PRINT "You'll have to force it open.": GOTO Lp12
IF k = -1 THEN PRINT "It won't open.": GOTO Lp12
'
a$ = "You've opened the " + a$(a) + "."
DoorOpen1:
a%(a, 6) = 0: a%(a, 7) = 0: GOTO Lp9
'
' **** 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: IF f = 0 THEN GOTO Err1
IF a = m OR a%(a, 2) <> 4 THEN s$ = "anything in that": GOTO Err3
'
f = 0: IF a%(a, 6) = 0 THEN GOTO Err2
IF a%(a, 8) < 1 THEN PRINT "You don't need to.": GOTO Lp12
IF a%(a, 7) >= a%(a, 8) THEN PRINT "It's full.": GOTO Lp12
IF a%(m, 3) > a%(a, 3) THEN PRINT "It won't fit.": GOTO Lp12
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
'
GOSUB Wtrem: 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: PRINT "(The "; a$(m); " goes out.)": GOSUB Lp4
PRINT "Done.": GOTO Lp12
'
' **** Read command ****
'
ItemRead:
IF lt = 0 THEN GOTO Main
GOSUB CheckSub: GOSUB Asearch0: IF f = 0 THEN GOTO Err1
IF a = 17 THEN
  COLOR 2: PRINT "The scroll crumbles as you unroll it.": COLOR 3
  GOSUB Wtrem: a%(a, 4) = 0: GOTO Lp12
END IF
IF a = 11 THEN
  PRINT "The label is worn, but you can make out:": GOSUB Lp4
  PRINT SPC(10); : COLOR 0, 2: PRINT SPC(12); : COLOR 2, 0: PRINT
  PRINT SPC(10); : COLOR 0, 2: PRINT " MAG C  G S "; : COLOR 2, 0: PRINT
  PRINT SPC(10); : COLOR 0, 2: PRINT SPC(12); : COLOR 3, 0: PRINT
  l = l + 2: GOTO Lp12
END IF
IF a%(a, 2) <> 7 THEN GOTO Err3
IF a%(a, 7) = 0 THEN GOTO Err2
IF a%(a, 4) = em THEN a%(a, 4) = ro: a%(a, 0) = 1
COLOR 2
FOR x = 1 TO a%(a, 6)
   r = a%(a, 5) + x - 1: GOSUB Effect
NEXT
IF a = 14 THEN
  d%(1) = RND * 50 + 25: GOSUB Wtrem: a%(a, 4) = 0
  PRINT "The "; a$(a); " vanishes!": GOSUB Lp4
END IF
COLOR 3: GOTO Pfoe
'
' **** 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.": GOTO Main0
END IF
GOSUB ItemTake: IF a%(a, 4) <> -1 THEN GOTO Main
IF a = 3 THEN PRINT "It is too hot to fight with.": GOTO Lp12
m%(0, 8) = a: GOSUB Pu0: PRINT a$; "readied.": GOSUB Lp4: GOTO Pfoe
'
' **** Remove command ****
'
Remove:
IF lt = 0 THEN GOTO Main
GOSUB CheckSub: ha = -999: wh = ha: em = ha: GOSUB Asearch2
IF f = 0 THEN GOTO Remove1
'
' ** Remove armor **
'
IF a = sh THEN m%(0, 7) = m%(0, 7) - 1: sh = 0
IF a = ar THEN m%(0, 7) = m%(0, 7) - a%(a, 5) / 2: ar = 0
a%(a, 4) = -1
GOSUB Pu0: PRINT a$; "removed.": GOTO Lp12
'
' ** 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
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.": GOSUB Lp4
IF a%(a, 0) = 0 THEN a%(a, 0) = 1: r = a: GOSUB DiskRead2
IF m = 15 AND a%(m, 7) = 0 THEN
  COLOR 2: PRINT "The chest vanishes!": COLOR 3: GOSUB Lp4
  a = m: GOSUB Wtrem: a%(a, 4) = 0
END IF
GOTO Pfoe
'
' **** Use command ****
'
Use:
IF lt = 0 THEN GOTO Main
GOSUB CheckSub: GOSUB Asearch0: IF f = 0 THEN GOTO Err1
IF a = 10 THEN
  a$ = "On what": GOSUB CheckSub2: s$ = s2$
  GOSUB Asearch0: IF f = 0 THEN GOTO Err1
  IF a <> 2 THEN PRINT "That's not what it's for!": GOTO Main0
  a%(2, 6) = 0: a%(2, 7) = 0: a = 10: GOSUB Wtrem: a%(a, 4) = 0
  COLOR 0, 2: PRINT "    B O O M ! !    "; : COLOR 3, 0: PRINT : GOSUB Lp4
  PRINT "The explosion opened the door!": GOTO Lp12
END IF
IF a <> 26 THEN PRINT "Try another command.": GOTO Lp12
'
'  Use Wheel
'
Wheel:
PRINT "Bet (G)old, (H)ardiness, (A)gility, (C)harisma, or (N)othing: ";
BS = POS(0): CC = 0: w2 = 0
DO
   CC = CC + 1
   IF CC = CC1 THEN PRINT "/"; : LOCATE CSRLIN, BS
   IF CC = CC2 THEN PRINT CHR$(179); : LOCATE CSRLIN, BS
   IF CC = CC3 THEN PRINT "\"; : LOCATE CSRLIN, BS: CC = 0
   a$ = UCASE$(INKEY$)
LOOP UNTIL a$ = "G" OR a$ = "H" OR a$ = "A" OR a$ = "C" OR a$ = "N"
PRINT a$: GOSUB Lp4: IF a$ = "N" THEN GOTO Main
FOR a = 1 TO 4
   IF a$ = MID$("GHAC", a, 1) THEN w2 = a
NEXT
IF w2 = 1 THEN xm = gold
IF w2 = 2 THEN xm = m%(0, 1)
IF w2 = 3 THEN xm = m%(0, 2) - 1
IF w2 = 4 THEN xm = ch - 1
'
PRINT "You can bet 1-"; LTRIM$(STR$(xm)): PRINT
LINE INPUT "Bet how much?: "; a$: m2 = VAL(a$): l = 0: GOSUB Lp4
m2 = INT(m2): COLOR 2
IF m2 < 1 THEN PRINT "Get out of here!": COLOR 3: GOTO Lp12
IF m2 > xm THEN PRINT "You don't have that much!": COLOR 3: GOTO Lp12
PRINT "Bet "; LTRIM$(RTRIM$(STR$(m2))); "?"; : GOSUB Af1
IF s$ <> "y" THEN COLOR 3: GOTO Wheel
'
'  Wheel of Fortune routine
'    By Frank Black, June 1999
'
CLS
COLOR 2: PRINT : PRINT "THE WHEEL OF FORTUNE IS SPINNING..."
COLOR 0, 5: LOCATE 10, 34: PRINT SPC(12); : LOCATE 12, 34: PRINT SPC(12);
COLOR 9, 0
FOR a = 1 TO 5
   LOCATE Wheel(a, 1), Wheel(a, 2): PRINT Wheel$(a)
   LOCATE Wheel(a, 1), Wheel(a, 3): PRINT Wheel$(a)
   LOCATE Wheel(a, 1) + 1, Wheel(a, 2): PRINT Wheel$(a)
   LOCATE Wheel(a, 1) + 1, Wheel(a, 3): PRINT Wheel$(a)
NEXT
a = 0
rl = INT(RND * 25 + 20)
FOR m = 1 TO rl
   a = a + 1: IF a > 9 THEN a = 1
   IF a = 6 THEN a = 7
   w = a: f = 2: IF a > 5 THEN w = 10 - a + 1: f = 3
   COLOR 15, 12
   LOCATE Wheel(w, 1), Wheel(w, f): PRINT Wheel$(w)
   LOCATE Wheel(w, 1) + 1, Wheel(w, f): PRINT Wheel$(w)
   COLOR 14, 0: LOCATE 11, 34: PRINT Wheel$(w + 5)
   FOR x = 1 TO dly / 5 + m * (dly / 50): NEXT: SOUND 300, 1
   IF m < rl THEN
     COLOR 9, 0: LOCATE Wheel(w, 1), Wheel(w, f): PRINT Wheel$(w)
     LOCATE Wheel(w, 1) + 1, Wheel(w, f): PRINT Wheel$(w)
   END IF
NEXT
COLOR 14: LOCATE 20, 20: PRINT "You ";
IF w = 4 THEN PRINT "are dead!": COLOR 3: die = 1: GOTO Endgame
IF w = 1 OR w = 5 THEN PRINT "win double!": m2 = m2 * 2
IF w = 2 THEN PRINT "lose!": m2 = -m2
IF w = 3 THEN PRINT "have won!"
IF w2 = 1 THEN gold = gold + m2
IF w2 = 2 THEN m%(0, 1) = m%(0, 1) + m2
IF w2 = 3 THEN m%(0, 2) = m%(0, 2) + m2
IF w2 = 4 THEN
  ch = ch + m2
  IF ch < 10 AND m2 < 1 THEN
    COLOR 2: PRINT SPC(19); "You sure are getting ugly!"
  END IF
END IF
COLOR 3: LOCATE 23: GOSUB Lp6: CLS : LOCATE 24
IF w2 = 2 AND m2 < 1 THEN df = 0: GOSUB Mstatus
GOTO Pfoe
'
' **** Wear command ****
'
Wear:
IF lt = 0 THEN GOTO Main
GOSUB CheckSub: ha = -1: wh = ro: em = -999: GOSUB Asearch2
IF f = 0 THEN GOTO Err1
IF a%(a, 2) <> 11 THEN GOTO Err3
IF a%(a, 4) = ro THEN GOSUB ItemTake: IF a%(a, 4) <> -1 THEN GOTO Main
IF a%(a, 4) = em THEN a$ = "it": GOTO Wear2
IF a%(a, 5) = 0 THEN GOTO Wear1
'
IF a%(a, 5) = 1 THEN
  IF sh > 0 THEN a$ = "a shield": GOTO Wear2
  sh = a: m%(0, 7) = m%(0, 7) + 1: GOTO Wear1
END IF
IF ar <> 0 THEN a$ = "armor": GOTO Wear2
ar = a: m%(0, 7) = m%(0, 7) + a%(a, 5) / 2
'
Wear1:
a%(a, 4) = -999: GOSUB Pu0: PRINT a$; "worn.": GOTO Pfoe
'
Wear2:
PRINT "You're already wearing "; a$; "!": GOTO Main0
'---------------------------------------------------------------------------
'  Interaction commands
'
'  **** Attack command ****
'
Attack:
IF m%(0, 8) < 1 THEN PRINT "You must first ready a weapon!": GOTO Main0
GOSUB CheckSub:  GOSUB Msearch: ta = 0: IF f = 0 THEN GOTO AttackItem
'
' Attack a monster
'
AttackMon:
IF m%(m, 11) > 1 THEN
  GOSUB Af: IF s$ <> "y" THEN GOTO Main
  m%(m, 11) = m%(m, 11) - 1: GOSUB EnemyCheck
  IF m%(m, 11) = 1 THEN a$ = m$(m) + " get's angry!": GOSUB Lp10
END IF
'
of = 0: df = m: up = 0: GOSUB Battle: IF die = 1 THEN GOTO Endgame
IF hit AND up THEN
  w2 = a%(m%(0, 8), 6): a$ = m$(0): m = 0: GOSUB Pu2: a$ = a$ + wp$(w2)
  a$ = a$ + " ability just increased!": wa%(w2) = wa%(w2) + 1: GOSUB Lp10
END IF
GOTO Pfoe
'
'  Attack/blast open a door or container
'
AttackItem:
IF lt = 0 THEN GOTO Main
ha = ro: GOSUB Asearch1: IF f = 0 THEN GOTO Err4
'
m = a%(a, 2): k = 6 + ABS(m = 8)
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
IF m = 12 THEN
  GOSUB ItemGet3: m = a%(a, 5): IF ta = 1 THEN GOTO Blast1
  GOTO AttackMon
END IF
IF m <> 4 AND m <> 8 THEN
  a$ = "Why would you attack a " + a$(a) + "?": GOTO Lp8
END IF
IF a%(a, k) < 100 THEN PRINT "Nothing happens.": GOTO Lp12
'
w = m%(0, 8): x = 7: k = 6: D2 = 0: IF m = 4 THEN x = 6: k = 5
d = a%(w, 7): s = a%(w, 8): IF ta = 1 THEN d = 2: s = 5
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 - ABS(m = 8): a%(a, k) = 0
  a$ = "The " + a$(a) + " shatters open!": GOTO Lp9
END IF
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): x = a%(a, 7)
IF x > 0 AND x <= nm THEN
  IF m%(x, 5) = ro THEN PRINT m$(x); " won't let you!": GOTO Lp12
END IF
'
IF k > 0 AND k <= naf THEN
  x = a%(k, 4)
  IF x <> -1 AND x <> ro AND x <> -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: GOSUB Wtrem: a%(a, 4) = 0
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 k = 0 THEN GOTO Give1
'
' Give money
'
GiveMoney:
a$ = "Give " + LTRIM$(STR$(k)) + " gold pieces to " + m$(m) + ".": GOSUB Lp10
PRINT "Are you sure?"; : GOSUB Af1: IF s$ <> "y" THEN GOTO Main
'
IF gold < k THEN PRINT "You only have"; gold; "gold pieces.": GOTO Main0
'
gold = gold - k: a$ = m$(m) + " takes the money...": GOSUB Lp10
IF m%(m, 11) = 2 AND k >= 5000 THEN m%(m, 11) = 3: GOSUB Smile1
GOTO Give2
'
' Give an item
'
Give1:
a$ = "You give the " + a$(a) + " to " + m$(m) + "...": GOSUB Lp10
x = a%(a, 2): IF a = m%(0, 8) THEN m%(0, 8) = -1
IF (x = 6 OR x = 9) AND m%(m, 13) > 0 AND a%(a, 6) > 0 THEN GOTO GiveDrink
'
GOSUB Wtrem: a%(a, 4) = -m - 1
IF a = 3 THEN
  COLOR 2: PRINT "The trident burns "; m$(m); "!": COLOR 3
  d = 1: s = 6: a = 0: df = m: of = 0: m%(m, 11) = 1
  GOSUB EnemyCheck: GOSUB Damage0
END IF
IF m%(m, 8) < 0 AND (x = 2 OR x = 3) AND a <> 3 THEN
  m%(m, 8) = a: a$ = m$(m) + " readies " + a$(a) + ".": GOSUB Lp10
END IF
IF m%(m, 11) < 3 THEN m%(m, 11) = 100 + m%(m, 11) * (30 + a%(a, 1) / 100)
'
Give2:
GOSUB EnemyCheck: GOTO Pfoe
'
' Give something drinkable
'
GiveDrink:
a%(a, 6) = a%(a, 6) - 1
a$ = m$(m) + " takes a " + MID$("drinkbite", ABS(a%(a, 2) = 9) * 5 + 1, 5)
a$ = a$ + " and hands it back."
IF x = 9 AND a%(a, 6) = 0 THEN
  a$ = m$(m) + " eats it all.": GOSUB Wtrem: a%(a, 4) = 0
END IF
GOSUB Lp10
'
IF m%(m, 11) < 3 THEN
  m%(m, 11) = 140 + 60 * m%(m, 13) / m%(m, 1): GOSUB EnemyCheck
  IF m%(m, 11) = 3 THEN GOSUB Smile1
END IF
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$ = "From whom": GOSUB CheckSub2
a$ = s$: s$ = s2$: GOSUB Msearch: IF f = 0 THEN GOTO Err4
s$ = a$: wh = -m - 1: ha = -m - 1000: em = wh: GOSUB Asearch2
IF f = 0 THEN a$ = m$(m) + " doesn't have it.": GOTO Lp8
IF m%(m, 11) < 3 THEN GOSUB Smile1: GOTO Pfoe
'
PRINT "Okay.": GOSUB Lp4: GOSUB ItemTake1: IF a%(a, 4) <> -1 THEN GOTO Main
IF a = m%(m, 8) THEN m%(m, 8) = -1
GOSUB Pu0: : PRINT a$; "taken.": GOSUB Lp4:
IF a%(a, 0) = 0 THEN a%(a, 0) = 1: GOSUB Lp1: r = a: GOSUB DiskRead2
IF m%(0, 8) < 1 AND (a%(a, 2) = 2 OR a%(a, 2) = 3) THEN GOTO Ready
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: GOSUB Lp1: GOTO Pfoe
'
Smile1:
PRINT m$(m); : IF m%(m, 3) > 1 THEN PRINT "s";
IF m%(m, 11) = 2 THEN
  PRINT " "; sm$(2); : IF m%(m, 3) > 1 THEN PRINT " you."
  IF m%(m, 3) = 1 THEN PRINT "s you."
  GOSUB Lp2: RETURN
END IF
IF m = 4 THEN PRINT " oozes"; : GOTO Smile2
IF m = 7 THEN PRINT " mumbles"; : GOTO Smile2
IF m = 11 THEN PRINT " grunts"; : GOTO Smile2
PRINT " "; sm$(m%(m, 11)); : IF m%(m, 3) = 1 THEN PRINT "s";
Smile2:
PRINT " at you.": GOTO Lp2
'---------------------------------------------------------------------------
' Miscelaneous commands
'
' **** Inventory ****
'
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) = 3 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
     GOSUB Pu0: PRINT " "; a$: 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
     GOSUB Pu0: PRINT " "; a$;
     IF m > 0 AND a%(a, 4) = wh THEN PRINT "  (Being worn)";
     COLOR 2: IF a = m%(m, 8) THEN PRINT "   [Ready Weapon]";
     IF a = ls THEN 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
IF m = 0 THEN PRINT LTRIM$(STR$(gold)); " gold pieces": GOSUB Lp4
df = m: D2 = 0: GOSUB Mstatus: GOTO Pfoe
'
' Show items inside of container
'
Inv3:
IF a%(a, 6) <> 1 THEN PRINT "  (Closed)"; : RETURN
GOSUB Lp1
'
Inv4:
xm = a + 1000: m2 = 0: PRINT "(This contains:)": GOSUB Lp2: of = 0
FOR a2 = 1 TO na
   IF a%(a2, 4) = xm THEN
     xx$ = a$(a2): IF a2 = 21 THEN xx$ = "coins"
     PRINT " --- "; UCASE$(LEFT$(xx$, 1)); MID$(xx$, 2)
     GOSUB Lp2: of = 1
   END IF
NEXT
IF of = 0 THEN PRINT " --- (Nothing)": GOSUB Lp2
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, 24: PRINT "Gold:"; gold
LOCATE 10, 56: 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: "; s$; " Gronds"
'
' Add your own special stuff here
'
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 s$ <> "" THEN GOTO Examine
IF lt = 0 THEN GOTO Main
r = ro: GOSUB DiskRead1: 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$ = "Neamo" AND ro = 9 THEN
  COLOR 2: PRINT "The square glows a bright red...": GOSUB Lp4
  r = 5: GOSUB Effect: COLOR 3: r2 = INT(RND * 30) + 1: GOTO Move2
END IF
IF s$ = "**open**" AND sa%(4) < 1 AND a%(1, 4) = ro AND a%(1, 7) = 1 THEN
  a%(1, 6) = 0: a%(1, 7) = 0
  PRINT "The iron door swings open!": COLOR 3: GOTO Lp12
END IF
'
' Spell of Trezore
'
IF s$ = "Trezore" AND d%(1) > 0 THEN
  rl = 100: GOSUB RollDice2
  IF rl + 20 < d%(1) THEN PRINT "Your spell failed.": GOTO Lp12
  rl = 5: GOSUB RollDice2
  IF rl = 1 AND t(1) > 0 THEN
    rl = nr - 1: GOSUB RollDice2: IF rl = ro THEN rl = rl + 1
    FOR m = 1 TO nm
       IF m%(m, 5) = ro AND m%(m, 11) = 1 THEN
         m%(m, 5) = rl: COLOR 2:
         PRINT m$(m); " vanishes in a puff of smoke!": COLOR 3: GOSUB Lp4
       END IF
    NEXT
    GOSUB EnemyCheck: GOTO Pfoe
  END IF
  IF rl = 2 AND t(3) > m%(0, 1) THEN
    rl = nr - 1: GOSUB RollDice2: IF rl = ro THEN rl = rl + 1
    FOR m = 1 TO nm
       IF m%(m, 5) = ro AND m%(m, 11) = 3 THEN
         m%(m, 5) = rl: COLOR 2
         PRINT m$(m); " vanishes in a puff of smoke!": COLOR 3: GOSUB Lp4
       END IF
    NEXT
    GOSUB EnemyCheck: GOTO Pfoe
  END IF
  IF rl = 3 THEN r = 3: GOSUB Effect: GOTO Pfoe
  IF rl = 4 AND db > 0 THEN
    f = 0
    FOR a = db TO naf
       IF a%(a, 4) = ro THEN
         a%(a, 4) = 0: m = a - db + 1: m%(m, 5) = ro: f = 1: COLOR 2
         PRINT m$(m); " comes back to life!": COLOR 3: GOSUB Lp4
       END IF
    NEXT
    IF f = 1 THEN GOSUB EnemyCheck: GOTO Pfoe
  END IF
  IF na > naf THEN
    FOR a = naf + 1 TO na
       IF a%(a, 2) = 11 AND LCASE$(LEFT$(a$(a), 7)) <> "purple " THEN
         a$(a) = "purple " + a$(a)
       END IF
    NEXT
  END IF
  PRINT "All your clothing suddenly turns bright purple!": GOTO Lp12
END IF
GOTO Pfoe
'
' **** Blast spell ****
'
Blast:
s = 1: GOSUB SpellCast: IF suc = 0 THEN GOTO Pfoe
GOSUB CheckSub: GOSUB Msearch: ta = 1: IF f = 0 THEN GOTO AttackItem
'
Blast1:
IF m%(m, 11) <> 1 THEN
  GOSUB Af: IF s$ <> "y" THEN GOTO Main
  m%(m, 11) = m%(m, 11) - 1: GOSUB EnemyCheck
  IF m%(m, 11) = 1 THEN a$ = m$(m) + " get's angry!": GOSUB Lp10
END IF
'
PRINT "ZAP!  Direct hit!": GOSUB Lp4
s = 5: d = 2: df = m: a = 0: GOSUB Damage0: GOTO Pfoe
'
' **** Heal spell ****
'
Heal:
s = 2: GOSUB SpellCast: IF suc = 0 THEN GOTO Pfoe
m = 0: IF s$ <> "" THEN GOSUB Msearch: IF f = 0 THEN GOTO Err4
IF m%(m, 13) > 0 THEN
  m = m: GOSUB Pu2: a$ = a$ + "health improves!": GOSUB Lp0
  rl = 12: GOSUB RollDice2: m%(m, 13) = m%(m, 13) - rl
  IF m%(m, 13) < 0 THEN m%(m, 13) = 0
END IF
df = m: D2 = 0: GOSUB Mstatus: GOTO Pfoe
'
' **** Speed spell ****
'
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 spell ****
'
Power:
s = 4: GOSUB SpellCast: IF suc = 0 THEN GOTO Pfoe
COLOR 2
IF a%(1, 4) = ro AND a%(1, 7) = 1 THEN
  a%(1, 6) = 0: a%(1, 7) = 0
  PRINT "The iron door swings open!": COLOR 3: GOTO Lp12
END IF
rl = 4: GOSUB RollDice2
IF rl = 1 THEN PRINT "A loud hissing noise errupts beneath you!"
IF rl = 2 THEN PRINT "You see a bright flash of light in the distance!"
IF rl = 3 THEN PRINT "You hear a loud whistling in your ears!"
IF rl = 4 THEN PRINT "You hear a loud sonic boom which echoes all around you!"
COLOR 3: GOTO Lp12
'
' **** Hints command ****
'
Hints:
PRINT "Your question?": GOSUB Lp4
PRINT "   1- "; h$(1): GOSUB Lp2
FOR r = 17 TO 20
   PRINT "   "; LTRIM$(RTRIM$(STR$(r - 15))); "- "; MID$(h$(r), 37)
   GOSUB Lp2
NEXT
GOSUB Lp1: LINE INPUT "Your choice?:"; a$: l = 0: r = INT(VAL(a$))
IF r > 1 THEN r = r + 15
IF r <> 1 AND ((r > 1 AND r < 17) OR r > 20 OR r < 1) THEN GOTO Main
'
GOSUB Lp1: COLOR 2: PRINT h$(r): COLOR 3: GOSUB Lp4
OPEN "HINTS.DSC" FOR RANDOM AS #1 LEN = 255
a = h%(r, 1) + h%(r, 2) - 1: s$ = ""
FOR m = h%(r, 1) TO a
   GET #1, m, DS: a$ = RTRIM$(DS.TEXT): GOSUB Lp10
   IF m < a THEN
     PRINT "Another? (Y/N):";
     DO
     s$ = LCASE$(INKEY$)
     LOOP UNTIL s$ = "y" OR s$ = "n"
     LOCATE CSRLIN, 1: PRINT SPC(16); : LOCATE CSRLIN, 1: l = 0
     IF s$ <> "y" THEN m = a
   END IF
NEXT
CLOSE #1: GOTO Main0
'
' **** Save game ****
'
GameSave:
OPEN "GAMEDIR.DAT" FOR INPUT AS #1: INPUT #1, a: IF a < 0 THEN a = 0
FOR m = 1 TO 5: LINE INPUT #1, gm$(m): NEXT
CLOSE #1: PRINT "Saved games:": GOSUB Lp4
FOR m = 1 TO 5
   PRINT " "; LTRIM$(RTRIM$(STR$(m))); "- "; gm$(m): GOSUB Lp2
NEXT: PRINT 6; "- (Don't save, return to game)": GOSUB Lp4
'
INPUT "Enter 1-6 for saved position:"; a$: m = INT(VAL(a$)): l = 0
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
'
IF m = a + 1 THEN a = a + 1
IF gm$(m) <> "(none)" THEN
  PRINT "Enter a new description for save?"; : GOSUB Af1
  IF s$ <> "y" THEN GOTO GameSave1
END IF
PRINT "Enter new description:": GOSUB Lp4: LINE INPUT "-->"; gm$(m)
l = 1: gm$(m) = LEFT$(gm$(m), 40)
'
GameSave1:
OPEN "GAMEDIR.DAT" FOR OUTPUT AS #1: PRINT #1, a
FOR k = 1 TO 5: PRINT #1, gm$(k): NEXT: CLOSE #1
'
a$ = "GAME" + LTRIM$(RTRIM$(STR$(m))) + ".SAV"
OPEN a$ FOR OUTPUT AS #1
FOR a = 1 TO na
   FOR m = 0 TO 8: PRINT #1, a%(a, m): NEXT
NEXT
FOR m = 0 TO nm
   FOR a = 0 TO 15: PRINT #1, m%(m, a): NEXT
NEXT
FOR r = 1 TO nr
   FOR m = 0 TO 11: PRINT #1, r%(r, m): NEXT
NEXT
FOR a = 1 TO 4: PRINT #1, t(a), sa%(a), sp%(a): NEXT
FOR a = 1 TO 5: PRINT #1, wa%(a): NEXT
FOR a = 0 TO 20: PRINT #1, d%(a): NEXT
PRINT #1, ac, ae, ar, bank, ch, die, ea, gold, ls, lt, nl, r3, ro, sex, sh
PRINT #1, Speed, wt
IF na > naf THEN
  FOR a = naf + 1 TO na: PRINT #1, a$(a): NEXT
END IF
CLOSE #1: PRINT "Game saved.": GOSUB Lp4: GOTO Main
'---------------------------------------------------------------------------
' **** Restore saved game ****
'
GameRestore:
OPEN "GAMEDIR.DAT" FOR INPUT AS #1: INPUT #1, a
FOR m = 1 TO 5: LINE INPUT #1, gm$(m): NEXT: CLOSE #1
PRINT "Saved games:": GOSUB Lp4
FOR m = 1 TO 5
   PRINT " "; LTRIM$(RTRIM$(STR$(m))); "- "; gm$(m): GOSUB Lp2
NEXT: PRINT 6; "- (Don't restore, return to game)": GOSUB Lp4
INPUT "Enter 1-6 to restore a position:"; a$: m = INT(VAL(a$)): l = 0
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.": GOTO GameRestore
'
a$ = "GAME" + LTRIM$(RTRIM$(STR$(m))) + ".SAV"
OPEN a$ FOR INPUT AS #1
FOR a = 1 TO na
   FOR m = 0 TO 8: INPUT #1, a%(a, m): NEXT
NEXT
FOR m = 0 TO nm
   FOR a = 0 TO 15: INPUT #1, m%(m, a): NEXT
NEXT
FOR r = 1 TO nr
   FOR m = 0 TO 11: INPUT #1, r%(r, m): NEXT
NEXT
FOR a = 1 TO 4: INPUT #1, t(a), sa%(a), sp%(a): NEXT
FOR a = 1 TO 5: INPUT #1, wa%(a): NEXT
FOR a = 0 TO 20: INPUT #1, d%(a): NEXT
INPUT #1, ac, ae, ar, bank, ch, die, ea, gold, ls, lt, nl, r3, ro, sex, sh
INPUT #1, Speed, wt
IF na > naf THEN
  FOR a = naf + 1 TO na: LINE INPUT #1, a$(a): NEXT
END IF
CLOSE #1: cz$ = "": r2 = ro: GOTO Move2
'
' **** Quit, leave the Eamon system ****
'
Quit:
OPEN "GAMEDIR.DAT" FOR INPUT AS #1: INPUT #1, a: CLOSE #1
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 Af1
IF s$ <> "y" THEN GOTO Main
CLS : CHDIR "..": RUN "STARTUP.BAS"
'---------------------------------------------------------------------------
' **** End of game routines ****
'
Endgame:
GOSUB Lp1: GOSUB Lp6
IF die = 0 THEN
  PRINT "Leave this adventure?"; : GOSUB Af1: 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
'
IF ar > 1 AND ar <= na THEN a%(ar, 4) = 0: a = a%(ar, 5)
IF sh > 1 AND sh <= na THEN a%(sh, 4) = 0: m = 1
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) < 2000 THEN
     k = a%(a, 4) - 1000
     IF a%(k, 4) = -1 AND (a%(a, 0) > 0 OR a%(k, 6) = 1) 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
'
s$ = "Lord William Missilefire"
GOSUB Lp7: a$ = "As you enter the Main Hall, " + s$ + " approaches you "
a$ = a$ + "and says, " + q$ + "You have too many weapons -- 4 is the "
a$ = a$ + "legal limit." + q$: GOSUB Lp0: 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): GOSUB Pu1: PRINT RTRIM$(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:
s$ = "Sam Slicker"
GOSUB Lp7: a$ = "You deliver your goods to " + s$ + ", the local "
a$ = a$ + "buyer of treasure.  He looks them over...": GOSUB Lp10
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: GOSUB Pu0: PRINT a$;
     s$ = "is": IF RIGHT$(a$(a), 1) = "s" THEN s$ = "are"
     PRINT s$; " worth "; : s$ = LTRIM$(RTRIM$(STR$(m))) + " gold pieces."
     IF m < 1 THEN s$ = "nothing."
     PRINT s$: GOSUB Lp4
   END IF
NEXT
'
GOSUB Lp1: PRINT "He pays you "; tp; " gold pieces total.": GOSUB Lp4
gold = INT(gold + tp): IF gold < 0 THEN gold = 0
GOSUB Lp6
EXIT SUB
'
' 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 EXIT SUB
IF a = 2 THEN RUN
GOTO GameRestore
'---------------------------------------------------------------------------
'
' Most-useful routines and subroutines
'
' Read text from DESC file
'
Effect:
GET #5, r + adj4, DS: GOTO DiskRead4
'
DiskRead1:
GET #2, r + adj1, DS: GOTO DiskRead4
DiskRead2:
GET #3, r + adj2, DS: GOTO DiskRead4
DiskRead3:
IF r = 17 AND d%(12) = 0 THEN d%(12) = 3
IF r = 18 AND d%(13) = 0 THEN d%(13) = 1
GET #4, r + adj3, DS: GOTO DiskRead4
'
DiskRead4:
a$ = RTRIM$(DS.TEXT)
IF MID$(a$, LEN(a$) - 2, 1) = "*" THEN
  r = VAL(RIGHT$(a$, 2)): a$ = LEFT$(a$, LEN(a$) - 3)
  GOSUB Lp0: GOTO Effect
END IF
GOSUB Lp0: GOTO Lp1
'
' Print a$ without wrap-around
'
Lp0:
xm = 0: 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: xm = 1
   END IF
NEXT: IF xm = 1 THEN GOTO Lp0
COLOR 7: PRINT "Word too long error!": COLOR 3: GOTO Lp4
'----------------------------------------------------------------------------
' 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
zz$ = INKEY$: l = 0: RETURN
'
Lp7:
  CLS : l = 0: RETURN
'
' Redundant stuff
'
Lp8:
GOSUB Lp10: GOTO Main
'
Lp9:
GOSUB Lp10: GOTO Pfoe
'
Lp10:
GOSUB Lp0: GOTO Lp1
'
Lp11:
GET #5, r, DS: a$ = RTRIM$(DS.TEXT): GOSUB Lp0: RETURN
'
Lp12:
GOSUB Lp4: GOTO Pfoe
'----------------------------------------------------------------------------
'
' Capitalize a$
'
Pu0:
a$ = a$(a)
Pu1:
a$ = UCASE$(LEFT$(a$, 1)) + MID$(a$, 2) + " ": RETURN
'
' Make a$ possessive
'
Pu2:
a$ = m$(m) + MID$("'s'", ABS(LCASE$(RIGHT$(m$(m), 1)) = "s") * 2 + 1, 2) + " "
RETURN
'---------------------------------------------------------------------------
' Get an item before doing something with it (Ready/Wear/Etc.)
'
ItemTake:
IF a%(a, 4) = -1 THEN RETURN
PRINT "(Taking it first.)"
'
ItemTake1:
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
'----------------------------------------------------------------------------
' Decrement WT if artifact is carried
'
Wtrem:
wt = wt - a%(a, 3) * ABS(a%(a, 4) = -1): RETURN

'----------------------------------------------------------------------------
' Player input error messages
'
Err0:
PRINT "Movement commands:"
FOR C = 1 TO nd: PRINT UCASE$(C$(C)), : NEXT
PRINT UCASE$(C$(11)): PRINT '
PRINT "Artifact manipulation:"
FOR C = 12 TO 25: PRINT UCASE$(C$(C)), : NEXT: PRINT : PRINT
PRINT "Interactive:"
FOR C = 26 TO 32: PRINT UCASE$(C$(C)), : NEXT: PRINT : PRINT
PRINT "Miscelaneous:"
FOR C = 33 TO nc: PRINT UCASE$(C$(C)), : NEXT: PRINT : PRINT
l = 99: GOTO Main0
'
Err1:
PRINT "You don't have it and it'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
'
Af:
PRINT "Attack non-enemy?";
Af1:
LINE INPUT "  (Y/N):"; s$: s$ = LTRIM$(RTRIM$(LCASE$(s$)))
s$ = LEFT$(s$, 1): IF s$ <> "y" AND s$ <> "n" THEN GOTO Af1
l = 0: GOTO Lp1
'---------------------------------------------------------------------------
' Synonym checker
'
Synonym:
SL = LEN(s$): sy$ = "": sy = 0
IF ro = 33 THEN sy$ = "wall": sy = 29: GOSUB Synonym1
IF ro = 33 THEN sy$ = "blocks": sy = 29: GOSUB Synonym1
IF ro = 33 THEN sy$ = "squares": sy = 29
IF ro = 25 THEN sy$ = "inscription": sy = 37
GOSUB Synonym1: RETURN
Synonym1:
IF LEFT$(sy$, SL) = s$ OR RIGHT$(sy$, SL) = s$ THEN s$ = LCASE$(a$(sy))
RETURN
'----------------------------------------------------------------------------
' See who folows player
'
MoveMons:
FOR xm = 1 TO nm
   IF m%(xm, 5) = r3 THEN
     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 THEN m%(xm, 5) = ro
     IF m%(xm, 11) = 1 THEN
       GOSUB RollDice: IF rl <= m%(xm, 4) THEN m%(xm, 5) = ro
     END IF
   END IF
MoveMon1:
NEXT: RETURN
'
' Enemies in room?
'
EnemyCheck:
t(1) = 0: t(2) = 0: t(3) = m%(0, 1)
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: 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!": sa%(s) = 5: GOTO Lp10
END IF
'
IF suc = 0 THEN PRINT "Nothing happened.": GOTO Lp2
'
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 " + UCASE$(C$(C)) + " just increased by 2!"
  GOSUB Lp0: GOSUB Lp1
END IF
IF sa%(s) > 9 THEN sa%(s) = sa%(s) / 2
RETURN
'---------------------------------------------------------------------------
' Get a random roll between 1 and RL
'
RollDice:
rl = 100
RollDice2:
rl = INT(RND * rl + 1): 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
'---------------------------------------------------------------------------
' 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 AND RIGHT$(s$, 1) = "s" AND SL > 1 THEN
    s$ = LEFT$(s$, SL - 1): GOTO Msearch0
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: IF f = 1 THEN xm = a
     END IF
   END IF
Asearch3:
NEXT: IF f = 1 THEN s$ = a$(a)
IF f > 1 THEN
  f = 0: a$ = "(Do you mean " + q$ + a$(xm) + q$ + " or " + q$
  a$ = a$ + a$(a) + q$ + "?)": GOSUB Lp0
END IF
RETURN
'---------------------------------------------------------------------------
' Monster tries to get a weapon
'
GetWep:
IF m%(of, 6) = -2 THEN RETURN
xm = -of - 1: 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
END IF
w = 0
FOR x = 4 TO na
   IF a%(x, 4) = xm 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
'
FOR x = 1 TO na
   IF a%(x, 4) = ro THEN
     IF (a%(x, 2) = 2 OR a%(x, 2) = 3) THEN
       xm = a%(x, 7) * a%(x, 8)
       IF a%(x, 0) = 1 AND xm > 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
IF m%(of, 6) = -1 AND m9 = 1 THEN GOTO Battle0
RETURN
'---------------------------------------------------------------------------
'  Combat routine
'
Battle:
  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
'
  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 hit = 1: GOTO Battle1
  a2 = 0
  IF m%(df, 8) > 0 THEN a2 = a%(m%(df, 8), 6)
  IF 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 "A critical hit!": GOSUB Lp2: r2 = INT(RND * 100) + 1
  IF r2 < 51 THEN a = 0: GOTO Damage0
  rl = 1.5: IF r2 > 85 THEN rl = 2
  IF r2 > 95 THEN rl = 3
  IF r2 = 100 THEN rl = m%(df, 1)
  s = rl * s
Damage0:
  D2 = 0
  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
Damage1:
  IF D2 < 1 THEN PRINT "  Armor absorbs damage!": GOTO Lp4
'---------------------------------------------------------------------------
' Add damage/report monster's health
'
Mstatus:
a$ = "": IF m%(df, 3) > 1 THEN a$ = "One "
a$ = 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 "Mstatus err, "; xm%: GOTO Lp4
Ms1:
a$ = a$ + "in perfect health.": GOTO Lp10
Ms2:
a$ = a$ + "still in good shape.": GOTO Lp10
Ms3:
a$ = a$ + "hurting.": GOTO Lp10
Ms4:
a$ = a$ + "in pain.": GOTO Lp10
Ms5:
a$ = a$ + "badly injured.": GOTO Lp10
Ms6:
a$ = a$ + "at death's door, knocking loudly.": GOTO Lp10
'---------------------------------------------------------------------------
' Monster dies
'
Mdead:
a$ = a$ + "dead!"
IF m%(df, 3) > 1 THEN m%(df, 3) = m%(df, 3) - 1: m%(df, 13) = 0: GOTO Mdead2
'
IF df = 0 THEN die = 1: GOTO Lp10
m%(df, 8) = -1 * ABS(m%(df, 8) <> 0): m%(df, 5) = 0
m%(df, 3) = m%(df, 12): m%(df, 13) = 0
FOR a2 = 1 TO na
   IF a%(a2, 4) = -df - 1 OR a%(a2, 4) = -df - 1000 THEN a%(a2, 4) = ro
NEXT
'
Mdead0:
IF db > 0 AND db + nm - 1 <= naf THEN a%(df + db - 1, 4) = ro
'
Mdead2:
IF df = 17 THEN d%(12) = 2: IF m%(of, 11) = 3 THEN d%(12) = 1
IF df = 18 THEN d%(13) = 2
w = m%(df, 11): t(w) = t(w) - m%(df, 1): GOTO Lp10
END SUB

