'     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 v3.0
'
'         Edgar's Adventures by Frank Black
'
' Converted to Eamon Deluxe in 1997
' Last Update: 10 MAR 2005

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
  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
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 a, a$, a2, ac, ae, aname$, ar, bank, c, ch, cz$, d, d2, df, die
DIM SHARED ea, em, f, gold, ha, hit, k, l, m, mc, mr%, na, naf, nc
DIM SHARED nd, ne, nh, 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

OPEN "..\SETTINGS.DAT" FOR INPUT AS #1: INPUT #1, dly#, CC1#, CC2#, CC3#: CLOSE
'
'  Set up variable table
'
OPEN "NAME.DAT  " FOR INPUT AS #1
INPUT #1, nr, naf, ne, nm, aname$, nd, ver
CLOSE : a = 0: m = a: ro = m
nr = 49: naf = 65: nm = 30: ne = 54: na = naf
adj1 = 166: adj2 = 150: adj3 = 119: adj4 = 289
'
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$(6, 2), c$(nc), d%(200), m$(nm), m%(nm, 15)
DIM SHARED r%(nr, 6), r$(nr), rb$(6, 1), s%(2), sp$(2), sex$(2)
DIM SHARED sm$(3), t(4), wa%(5), wp%(na), wp$(5), gm$(5), i%(14)
'---------------------------------------------------------------------------
'  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
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
NEXT
'
'   Artifacts
'
FOR a = 1 TO na
   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: CLOSE
'
' Pre-set player values
'
m$(0) = "Edgar": m%(0, 1) = 25: m%(0, 2) = 22: m%(0, 7) = 1: m%(0, 8) = -1
ch = 22: ae = 30: gold = 0: wc = 40
FOR a = 1 TO 5: wa%(a) = 35: NEXT
'
'    Set starting variable values
'
FOR a = 0 TO 6
   FOR a2 = 0 TO 2: READ bv$(a, a2): NEXT
NEXT
FOR a = 0 TO 6
   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
m%(7, 13) = -999: a%(2, 7) = 1: a%(2, 8) = 4: a%(3, 6) = 4: a%(45, 6) = 6
ro = 22: r2 = 22: r3 = 22: q$ = CHR$(34)
sex$(0) = "Male": sex$(1) = "Female"
FOR a = 0 TO 14: READ i%(a): NEXT
FOR a = 0 TO 2: READ sp$(a), s%(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
'
' Randomize the RND seed
'
CLS : PRINT "(Base dungeon prog. v3.0)": 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
'
'  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
OPEN "NEW-MEAT" FOR RANDOM AS #4 LEN = 200: a = 1: GET #4, a, z: CLOSE
KILL "NEW-MEAT"
'
' Return to Test Bench
'
r = z.Status: z.Status = 1
IF r < 1 THEN CHDIR "..": CHDIR "DD": RUN "DDMENU"
'
' 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"
'
DATA 34,north,south,east,west,up,down,board,flee,drink,drop,eat
DATA examine,get,open,put,read,ready,remove,use,wear,attack,buy,free
DATA give,request,sell,smile,talk,inventory,look,hints,save,restore,quit
'
DATA lunges,tears,claws,swings,chops,swings,fires,shoots,fires,swings,swings
DATA swings,stabs,lunges,jabs,swings,chops,stabs,shoots,aims,shoots
'
DATA Missed,Missed,Parried,Missed,Missed,Missed,Parried,Missed,Parried,Missed
DATA Parried,Missed,Dodged,Missed
'
DATA growl,look,smile
'
DATA axe,missile weapon,club,spear,sword
'
DATA 12,13,15,16,17,18,19,22,24,27,30,31,32,35,36
DATA "magic missle",5,fireball,10,"thunder bolt",15

SUB Main
r2 = 22: GOTO Move2
'----------------------------------------------------------------------------
' Main Loop
'
Main0:
GOSUB Lp4
'
Main:
IF ro = 1 THEN df = 0: d2 = 3: GOSUB Damage1
IF die = 1 THEN GOTO EndGame
COLOR 12: GOSUB Lp1
'
' Give room name and description
'
Main3B:
PRINT r$(ro): 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 = 1: 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 AND a%(a, 7) > 0 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 AND a%(a, 7) > 0 THEN GOSUB Inv4
Main5B:
NEXT
'
' Get command
'
Com0:
GOSUB Lp1
IF ro = 32 AND m%(13, 5) = -1 THEN
  COLOR 3: r = 46: GOSUB Effect: m%(13, 5) = ro: m%(14, 5) = 44
  COLOR 12: GOSUB EnemyCheck: GOTO Main
END IF
IF m%(7, 5) = ro AND m%(7, 13) = -999 THEN
  COLOR 3
  IF a%(11, 4) <> 1008 OR a%(8, 4) <> ro THEN
    r = 1: GOSUB Effect: die = 1: GOTO EndGame
  END IF
  a%(11, 4) = 0: a%(8, 7) = 0: r = 2: m%(7, 13) = 0: GOSUB Effect: COLOR 12
END IF
Com1:
LINE INPUT ">"; a$: a$ = RTRIM$(LTRIM$(LCASE$(a$)))
l = 0: GOSUB Lp1
IF a$ = "" THEN
  a$ = cz$: LOCATE CSRLIN - 2, 2: 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, Board, Flee
ON c - 8 GOTO Drink, Drop, Drink, Examine, ItemGet, ItemOpen
ON c - 14 GOTO ItemPut, ItemRead, Ready, Remove, Use, Wear
ON c - 20 GOTO Attack, Buy, Free, Give, Request, Sell, Smile, Talk
ON c - 28 GOTO Inventory, Look, Hints, GameSave, GameRestore, Quit
'---------------------------------------------------------------------------
'  Pick foes
'
Pfoe:
IF die = 1 THEN GOTO EndGame
IF ro = 32 AND m%(13, 5) = 0 THEN r = 54: GOSUB Effect: r2 = 44: GOTO Move2
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:
IF of <> 19 AND of <> 30 THEN GOSUB Battle
IF of = 19 THEN
  k = INT(RND * 3)
  a$ = m$(of) + " throws a " + sp$(k) + " at " + m$(df) + "!"
  COLOR 14: GOSUB Lp0: COLOR 2: d2 = s%(k): PRINT " === "; : GOSUB Damage1
  COLOR 3
END IF
IF of = 30 THEN
  k = INT(RND * 10 + 1)
  IF k < 6 THEN
    COLOR 14: a$ = "Lich electrocutes " + m$(df) + "!": GOSUB Lp0
    COLOR 2: d2 = 8: PRINT " === "; : GOSUB Damage1: COLOR 3: GOTO Pfoe2AA
  END IF
  COLOR 14: a$ = "Lich terrifies " + m$(df) + "!": GOSUB Lp0: COLOR 2
  d2 = 3: a = m%(df, 8): PRINT " === ";
  IF a < 1 THEN GOSUB Damage1: COLOR 3: GOTO Pfoe2AA
  GOSUB WTRem: a%(a, 4) = ro: m%(df, 8) = -a - 1
  PRINT m$(df); " drops "; a$(a); "!": COLOR 3: GOSUB Lp4
END IF
Pfoe2AA:
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
GOTO Main
1994  REM 4/8/94 Kurt Cobain R.I.P.
'---------------------------------------------------------------------------
' **** Movement commands ****
'
' **** Directions ****
'
Move:
IF ro < 25 AND a%(6, 4) <> -999 THEN
  PRINT "OUCH!  The floor burns your feet!": GOTO Main0
END IF
r2 = r%(ro, c)
IF t(1) THEN PRINT "You can't do that with unfriendlies about!": GOTO Main0
'
MoveCheck:
IF r2 > 1000 THEN GOTO Move1
IF r2 > 0 AND r2 <= nr THEN GOTO Move2
IF r2 = -1 THEN PRINT "The door is locked.": GOTO Main0
IF r2 = -2 THEN PRINT "The Cyborg blocks your path!": GOTO Main0
IF r2 = -3 THEN r = 21: GOTO Lp14
IF r2 = -4 THEN r = 4: GOSUB Effect: die = 1: GOTO EndGame
IF r2 = -5 THEN r = 22: GOTO Lp14
IF r2 = -6 THEN PRINT "You would drown.": GOTO Main0
IF r2 = -7 THEN r = 23: GOTO Lp14
IF r2 = -8 THEN
  IF a%(58, 4) <> -1 THEN r = 50: GOTO Lp14
  die = 0: GOTO EndGame
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 r2 = 0: GOTO MoveCheck
PRINT "The "; a$(a); " blocks the way!": GOTO Main0
'
' Go to another room
'
Move2:
IF r2 = 9 AND ro = 8 AND a%(18, 4) = r2 THEN
  a%(18, 4) = 0
  IF m%(7, 5) = 0 THEN m%(5, 5) = r2: GOTO Move3
  r = 3: GOSUB Effect: a%(4, 4) = r2: r%(9, 1) = 5: a%(30, 4) = r2
END IF
IF r2 = 35 THEN r4 = 16
IF r2 = 36 THEN r4 = 17
IF r2 = 38 THEN r4 = 18
IF ro = 23 THEN
  COLOR 2: PRINT "Coming out of the closet, I see.  <snicker>": COLOR 3: GOSUB Lp4
END IF
Move3:
r3 = ro: ro = r2: nx = 0: IF ro <> 32 THEN GOSUB MoveMons
GOSUB EnemyCheck
FOR a = 1 TO nd
   nx = nx + ABS(r%(ro, a) > 0 AND r%(ro, a) <= nr AND r%(ro, a) <> ro)
NEXT
GOTO Main
'============================================================================
' Board
'
Board:
IF t(1) THEN GOTO Move
GOSUB CheckSub: GOSUB Asearch0
IF f = 0 OR a <> 19 THEN s$ = "that": GOTO Err3
PRINT "You board the cargo ship.": GOSUB Lp4: r2 = 24: GOTO Move2
'============================================================================
'
' **** 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 ro = 32 THEN PRINT "You must fight until he falls!": 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

'
' **** 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 it all up.": GOSUB Lp4: GOSUB WTRem: a%(a, 4) = 0
END IF
'
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:
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
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
RETURN
'
'  **** Examine command ****
'
Examine:
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%(a, 2) = 12 THEN GOSUB ItemGet3: GOTO Main
r = a + 400: GOSUB DiskRead: 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
w = 0
IF a = 24 AND a%(25, 0) = 0 THEN a%(25, 4) = ro: w = 1
IF a = 63 AND a%(58, 0) = 0 THEN
  a%(58, 4) = ro: w = 1
  IF m%(30, 0) = 0 THEN m%(30, 5) = ro: GOSUB EnemyCheck
END IF
IF w = 1 THEN PRINT "You found something!": GOTO Main0
GOTO Pfoe
'
' ** Examine monster **
'
Examine1:
GOSUB Msearch: IF f = 0 THEN PRINT "You see nothing special.": GOTO Lp12
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
GOSUB Mstatus: GOTO Pfoe
'
'  **** The Get command ****
'
ItemGet:
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
GOSUB ItemGet3: GOSUB Lp4: GOTO Pfoe
'
ItemGet2:
FOR a = 1 TO na
   IF a%(a, 4) = ro THEN
     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) + 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 Lp4
IF a%(a, 3) = -999 THEN PRINT "You can't get that.": GOTO Lp4
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 m%(0, 8) < 1 AND (a2 = 2 OR a2 = 3) THEN
   m%(0, 8) = a: GOSUB Lp1: PRINT a$(a); " readied.": GOTO Lp4
END IF
GOTO Lp2
'
' **** Open command ****
'
ItemOpen:
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 = 31 AND (a%(26, 4) = ro OR a%(26, 4) = -1) THEN
  IF ro <> 7 THEN r = 7: GOTO Lp14
  IF r%(7, 1) = 4 THEN PRINT "The door is open.": GOTO Lp12
  r%(7, 1) = 4: PRINT "The door opens.": GOTO Lp12
END IF
IF a = 15 OR a = 31 THEN PRINT "You can't budge it.": GOTO Lp12
IF a = 63 AND m%(30, 0) = 0 THEN m%(30, 5) = ro: r2 = ro: GOTO Move2
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 a%(a, 7) = 0 THEN PRINT "It's already open.": GOTO Lp12
IF a = 15 OR a = 31 THEN PRINT "With what?": GOTO Main0
'
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:

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 THEN s$ = "anything in that": GOTO Err3
'
IF a = 35 THEN
  IF m <> 34 THEN PRINT "It won't fit.": GOTO Lp12
  a%(m, 4) = 0: COLOR 2: FOR x = 16 TO 20: r = x: GOSUB Effect: NEXT
  COLOR 3: r2 = 39: GOTO Move2
END IF
IF 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 a = 12 THEN
  IF d%(1) = 0 THEN d%(1) = m: GOTO Pt
  d%(2) = m
END IF
Pt:
PRINT "Done.": GOTO Lp12
'
' **** Read command ****
'
ItemRead:
GOSUB CheckSub: GOSUB Asearch0: IF f = 0 THEN GOTO Err1
IF a = 9 OR a = 20 OR a = 40 OR a = 41 OR a = 48 THEN
  PRINT "You can't seem to decipher the words.": GOTO Lp12
END IF
IF a = 23 THEN GOTO Examine
IF a%(a, 2) <> 7 THEN GOTO Err3
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
'
' **** 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 would make an awful weapon.": GOTO Main0
END IF
GOSUB ItemTake: IF a%(a, 4) <> -1 THEN GOTO Main
m%(0, 8) = a: GOSUB Pu0: PRINT a$; "readied.": GOSUB Lp4: GOTO Pfoe
'
' **** Remove command ****
'
Remove:
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:
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 m = 12 THEN PRINT "It's stuck.": GOTO Lp12
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 + 400: GOSUB DiskRead
GOTO Pfoe
'
' **** Use command ****
'
Use:
GOSUB CheckSub: GOSUB Asearch0: IF f = 0 THEN GOTO Err1
IF a <> 12 AND (a < 26 OR a > 29) AND a <> 40 AND a <> 41 AND a <> 47 AND a <> 48 THEN
  PRINT "Try another command.": GOTO Lp12
END IF
'
' Mutant machine
'
IF a = 12 THEN
  IF a%(a, 7) < 2 THEN r = 5: GOTO Lp14
  a = d%(1): m = d%(2): d%(1) = 0: d%(2) = 0
  a%(a, 4) = 0: a%(m, 4) = 0: a%(12, 7) = 0: r = 6: GOSUB Effect
  IF (a <> 10 AND a <> 14) OR (m <> 10 AND m <> 14) THEN
    m%(6, 5) = ro: r2 = ro: GOTO Move2
  END IF
  m%(7, 5) = ro: r2 = ro: GOTO Move2
END IF
'
' Key
'
IF a = 26 THEN
  IF ro <> 7 THEN r = 7: GOTO Lp14
  IF r%(7, 1) = 4 THEN PRINT "The door is open.": GOTO Lp12
  r%(7, 1) = 4: PRINT "The door opens.": GOTO Lp12
END IF
'
' Toilet
'
IF a = 27 THEN r = 9: GOTO Lp14
'
' Codecard
'
IF a = 28 THEN
  IF ro <> 10 THEN r = 8: GOTO Lp14
  IF r%(10, 4) = 9 THEN PRINT "The door is open.": GOTO Lp12
  r%(10, 4) = 9: r = 10: GOTO Lp14
END IF
'
' Pipe bomb
'
IF a = 29 THEN
  a$ = "Use it on whom": GOSUB CheckSub2: s$ = s2$: GOSUB Msearch
  IF f = 0 THEN
    GOSUB Asearch0: IF f = 0 OR a <> 18 THEN GOTO Err4
    r = 11: GOTO Lp14
  END IF
  IF m%(m, 11) > 1 THEN GOTO AttackMon
  GOSUB WTRem: a%(a, 4) = 0: df = m: d2 = 18
  COLOR 0, 3: PRINT "  B O O M ! !  "; : COLOR 3, 0: GOSUB Lp1: GOSUB Lp1
  GOSUB Damage1: GOTO Pfoe
END IF
'
' Tavern pass
'
IF a = 40 THEN
  IF ro <> 33 OR r%(33, 4) <> -7 THEN r = 25: GOTO Lp14
  r%(33, 4) = 32: r = 26: GOTO Lp14
END IF
'
' Palace pass
'
IF a = 41 THEN
  IF ro <> 30 OR r%(30, 1) <> -3 THEN r = 25: GOTO Lp14
  r%(30, 1) = 27: r = 27: GOTO Lp14
END IF
'
' Gate pass
'
IF a = 48 THEN
  IF ro <> 30 OR r%(30, 4) <> -5 THEN r = 25: GOTO Lp14
  r%(30, 4) = 29: r = 28: GOTO Lp14
END IF
'
' Shovel
'
PRINT "Digging ";
FOR x = 1 TO 8
   PRINT ".";
   FOR m# = 1 TO dly# * 2: NEXT
NEXT
IF ro <> 25 OR a%(36, 0) > 0 THEN PRINT " You find nothing.": GOTO Lp12
PRINT " You found something!": a%(36, 4) = ro: GOTO Lp12
'============================================================================
' **** 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
IF a%(a, 2) <> 11 THEN GOTO Err3
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
IF m%(0, 8) = 2 THEN
  IF a%(2, 0) > 5 THEN PRINT "The "; a$(2); " is out of energy!": GOTO Main0
  a%(2, 0) = a%(2, 0) + 1
END IF
GOSUB CheckSub:  GOSUB Msearch: ta = 0: IF f = 0 THEN GOTO AttackItem
'
' Attack a monster
'
AttackMon:
IF m%(m, 11) > 1 THEN r = 11: GOTO Lp14
'
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 a door or container
'
AttackItem:
ha = ro: GOSUB Asearch1: IF f = 0 THEN GOTO Err4
'
m = a%(a, 2): k = 6 + ABS(m = 8)
IF m = 12 THEN
  GOSUB ItemGet3: m = a%(a, 5): 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)
FOR a2 = 1 TO d: d2 = d2 + INT(RND * s) + 1: NEXT
a$ = "Wham!  You hit 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
'============================================================================
'  Buy
'
Buy:
IF ro <> 35 AND ro <> 36 AND ro <> 38 THEN
  PRINT "Nothing to buy here.": GOTO Main0
END IF
f = 0
PRINT "Right now he has:": GOSUB Lp2
FOR a = 1 TO na
   IF a%(a, 4) = -r4 - 1 THEN
     GOSUB Pu0: PRINT "   "; a$; "  ("; LTRIM$(RTRIM$(STR$(a%(a, 1)))); ")"
     f = 1: GOSUB Lp2
   END IF
NEXT
IF f = 0 THEN PRINT "Nothing you'd want."; q$: GOTO Lp12
PRINT "<Enter> to exit.": GOSUB Lp4
PRINT "You have "; LTRIM$(RTRIM$(STR$(gold))); " gold coins.": GOSUB Lp4
LINE INPUT "What to buy? >"; s$: s$ = LTRIM$(RTRIM$(LCASE$(s$)))
IF s$ = "" THEN GOTO Pfoe
wh = -r4 - 1: ha = wh: em = wh: GOSUB Asearch2
IF f = 0 THEN r = 24: GOTO Lp14
IF gold < a%(a, 1) THEN PRINT q$; "You can't afford that."; q$: GOTO Lp12
a%(a, 4) = ro: gold = gold - a%(a, 1)
GOSUB Lp1: PRINT q$; "Sold!"; q$: GOSUB Lp4: GOTO Buy
'
'  Sell
'
Sell:
IF ro <> 35 AND ro <> 36 AND ro <> 38 THEN
  PRINT "Nobody is interested.": GOTO Main0
END IF
GOSUB CheckSub: GOSUB Asearch: IF f = 0 THEN PRINT "You don't have it.": GOTO Main0
f = 0
FOR m = 0 TO 14
   IF a = i%(m) THEN f = 1
NEXT
IF f = 1 THEN r = 12: GOTO Lp14
IF a = 11 OR a = 14 OR a = 33 THEN r = 15: GOTO Lp14
m = a%(a, 2)
IF (m = 2 OR m = 3) AND r4 <> 18 THEN a$ = "weapons": GOTO Sell2
IF m = 11 AND r4 <> 17 THEN a$ = "armor": GOTO Sell2
IF r4 = 18 AND m <> 2 AND m <> 3 THEN a$ = "junk": GOTO Sell2
IF r4 = 17 AND m <> 11 THEN a$ = "junk": GOTO Sell2
IF a%(a, 1) = 0 THEN PRINT q$; "It's worthless."; q$: GOTO Lp12
PRINT "Sell the "; a$(a); "?"; : GOSUB AF1: IF s$ <> "y" THEN GOTO Pfoe
GOSUB WTRem: a%(a, 4) = 0: gold = gold + a%(a, 1)
IF a = m%(0, 8) THEN m%(0, 8) = -1
r = 1213 + ABS(a%(a, 1) > 10) + adj4: GOSUB Clerk2
a$ = a$ + " " + LTRIM$(RTRIM$(STR$(a%(a, 1)))) + " gold coins." + q$: GOTO Lp9
Sell2:
PRINT q$; "I don't buy "; a$; "."; q$: GOTO Lp12
'============================================================================
'
' **** Free command ****
'
Free:
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$ + ".": IF a = 32 THEN a$ = "You smash the device!"
GOSUB Lp0: m%(m, 5) = ro: GOSUB WTRem: a%(a, 4) = 0
GOSUB EnemyCheck: GOTO Pfoe
'
' **** Give command ****
'
Give:
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%(m, 11) < 2 THEN GOSUB Smile1: GOTO Pfoe
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
GOTO Give2
'
' Give an item
'
Give1:
IF a = 2 OR a = 21 THEN PRINT m$(m); " doesn't want it.": GOTO Lp12
IF m = 12 AND (a = 38 OR a = 49) THEN m2 = m%(m, 0): GOTO Talk0
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 m%(m, 8) < 0 AND (x = 2 OR x = 3) THEN
  m%(m, 8) = a: a$ = m$(m) + " readies " + a$(a) + ".": GOSUB Lp10
END IF
'
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:
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 + 400: GOSUB DiskRead
IF m%(0, 8) < 1 AND a%(a, 2) = 2 OR a%(a, 2) = 3 THEN GOTO Ready
GOTO Pfoe
'
' **** Smile command ****
'
Smile:
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";
PRINT " "; sm$(m%(m, 11)); : IF m%(m, 3) = 1 THEN PRINT "s";
PRINT " at you.": GOTO Lp2
'============================================================================
'  Talk
'
Talk:
GOSUB CheckSub:  GOSUB Msearch: IF f = 0 THEN GOTO Err4
m2 = m%(m, 0): IF m < 19 AND m > 15 THEN GOTO Buy
'
' Adventure Clerk
'
Talk0:
IF m = 12 THEN
  IF m2 > 5 THEN GOTO Talk1
  IF m2 < 2 THEN m%(m, 0) = 2: a%(48, 4) = ro: r = 29: GOTO Lp14
  IF m2 = 2 AND m%(9, 5) THEN r = 29: GOTO Lp14
  IF m2 = 2 THEN
    a = 49: GOSUB Clerk1: IF k = 0 THEN GOTO Pfoe
    m%(m, 0) = 3: gold = gold + 100: GOSUB WTRem: a%(a, 4) = 0: COLOR 2
    r = 32: GOSUB Effect: COLOR 3: m2 = 3: a%(47, 4) = ro: a%(50, 4) = ro
  END IF
  IF m2 = 3 AND a%(36, 0) = 0 THEN
    COLOR 2: r = 30: GOSUB Effect: r = 31: GOTO Lp14
  END IF
  a = 38: GOSUB Clerk1: IF k = 0 THEN GOTO Pfoe
  m%(m, 0) = 6: GOSUB WTRem: a%(a, 4) = 0: gold = gold + 500
  a%(41, 4) = ro: r = 33: GOTO Lp14
Clerk1:
  IF a%(a, 4) <> -1 AND a%(a, 4) <> ro THEN
    r = 34: GOSUB Clerk2: a$ = a$ + a$(a) + "." + q$
    GOSUB Lp10: k = 0: RETURN
  END IF
  k = 1: RETURN
Clerk2:
  GET #13, r - 1200, DS: a$ = RTRIM$(DS.TEXT): RETURN
END IF
'
' The King
'
IF m = 23 THEN
King:
  IF m2 = 3 AND a%(58, 0) = 0 THEN
    r = 44: GOSUB Effect: r = 45: GOSUB Effect
    PRINT "Thy name is now Sir Edgar.": GOTO Main0
  END IF
  IF m2 = 3 THEN
    a = 58: GOSUB Clerk1: IF k = 0 THEN GOTO Pfoe
    die = 0: GOTO EndGame
  END IF
  a%(39, 4) = ro: a%(40, 4) = ro: m2 = 3: m%(m, 0) = m2: m$(0) = "Sir Edgar"
  m%(0, 1) = 40: GOTO King
END IF
'
' Shipping Clerk
'
IF m = 21 THEN r = 49: GOTO Lp14
'
' Mad Adventurer
'
IF m = 10 THEN
  r = 48: GOSUB Effect: m%(m, 11) = 1: GOSUB EnemyCheck
  df = 0: of = m: GOSUB Battle: GOTO Main
END IF
Talk1:
PRINT "You exchange ";
PRINT MID$("pleasantries.insults!", ABS(m%(m, 11) = 1) * 13 + 1, 13)
GOSUB Lp4: GOTO Pfoe
'============================================================================
'
' Miscelaneous commands
'
' **** Inventory ****
'
Inventory:
IF s$ = "" THEN GOTO Inv1
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]";
     COLOR 3: IF a%(a, 2) = 4 AND (a%(a, 7) > 0 OR a%(a, 6) = 0) THEN GOSUB Inv3
     f = 1: GOSUB Lp1
   END IF
NEXT
IF f = 0 THEN PRINT " (Nothing)": GOSUB Lp2
IF m = 0 AND gold > 0 THEN PRINT LTRIM$(STR$(gold)); " gold coins": GOSUB Lp2
df = m: d2 = 0: GOSUB Lp1: 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
     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
RETURN
'
'  **** Look command ****
'
Look:
IF ro = 46 AND a%(64, 8) THEN
  a%(64, 7) = 0: a%(64, 8) = 0: a%(64, 4) = ro: GOTO Main
END IF
IF ro = 49 AND a%(65, 8) THEN
  a%(65, 7) = 0: a%(65, 8) = 0: a%(65, 4) = ro: GOTO Main
END IF
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
GOTO Pfoe
'
' **** Hints command ****
'
Hints:
PRINT "Your question?": GOSUB Lp4
PRINT "   1- "; h$(1): GOSUB Lp2
a = 1: m = 1: IF nh > 1 THEN a = 60: m = 73
IF a > 1 THEN
  FOR r = a TO m
     PRINT "   "; LTRIM$(RTRIM$(STR$(r - (a - 2)))); "- "; h$(r): GOSUB Lp2
  NEXT
END IF
GOSUB Lp1: LINE INPUT "Your choice?:"; a$: l = 0: r = INT(VAL(a$))
IF r > 1 THEN r = r + (a - 2)

IF r <> 1 AND ((r > 1 AND r < a) OR r > m 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 #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 " "; 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 #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 6: PRINT #2, r%(r, m): NEXT
NEXT
FOR a = 1 TO 4: PRINT #2, t(a): NEXT
FOR a = 1 TO 5: PRINT #2, wa%(a): NEXT
FOR a = 0 TO 200: PRINT #2, d%(a): NEXT
PRINT #2, ac, ae, ar, bank, ch, die, ea, gold, r3, r4, ro, sex, sh
PRINT #2, Speed, wt
PRINT #2, m$(0)
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 " "; 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 #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 6: INPUT #2, r%(r, m): NEXT
NEXT
FOR a = 1 TO 4: INPUT #2, t(a): NEXT
FOR a = 1 TO 5: INPUT #2, wa%(a): NEXT
FOR a = 0 TO 200: INPUT #2, d%(a): NEXT
INPUT #2, ac, ae, ar, bank, ch, die, ea, gold, r3, r4, ro, sex, sh
INPUT #2, Speed, wt
LINE INPUT #2, m$(0)
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 AF1
IF s$ <> "y" THEN GOTO Main
CLS : CHDIR "..": RUN "EAMONDX"
'---------------------------------------------------------------------------
' **** End of game routines ****
'
EndGame:
GOSUB Lp1: GOSUB Lp6: GOSUB Lp7
IF die = 0 THEN
  FOR x = 51 TO 53: r = x: COLOR 2: GOSUB Effect: COLOR 3: NEXT
  GOSUB Lp4: PRINT "Hit any key to exit...": GOSUB Lp4: GOSUB Lp6: EXIT SUB
END IF
'
' 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:
r = r + 1200
'
DiskRead:
IF r < 401 THEN GET #10, r + adj1, DS
IF r > 400 AND r < 801 THEN GET #11, r - 400 + adj2, DS
IF r > 800 AND r < 1201 THEN GET #12, r - 800 + adj3, DS
IF r > 1200 THEN GET #13, r - 1200 + adj4, DS
a$ = RTRIM$(DS.TEXT): 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 to 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:
GOSUB DiskRead: l = l - 1: LOCATE CSRLIN - 1, 1: RETURN
'
Lp12:
GOSUB Lp4: GOTO Pfoe
'
Lp14:
COLOR 2: GOSUB Effect: COLOR 3: GOTO Main
'----------------------------------------------------------------------------
'
' 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 8: PRINT UCASE$(c$(c)), : NEXT: PRINT : PRINT
PRINT "Artifact manipulation:"
FOR c = 9 TO 20: PRINT UCASE$(c$(c)), : NEXT: PRINT : PRINT
PRINT "Interactive:"
FOR c = 21 TO 28: PRINT UCASE$(c$(c)), : NEXT: PRINT : PRINT
PRINT "Miscelaneous:"
FOR c = 29 TO nc: PRINT UCASE$(c$(c)), : NEXT: PRINT : PRINT
PRINT "New commands: "; : COLOR 2: PRINT "BOARD, TALK, BUY, SELL": COLOR 3
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 a%(12, 4) = ro THEN sy$ = "machine": sy = 12
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
'---------------------------------------------------------------------------
' 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 AND w <> 2 THEN
    GOTO GetWep1
  END IF
END IF
w = 0
FOR x = 1 TO na
   IF a%(x, 4) = xm THEN
     IF (a%(x, 2) = 2 OR a%(x, 2) = 3) AND x <> 2 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) AND x <> 2 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 of = 25 OR of = 29 THEN m%(of, 8) = 60
IF of = 24 THEN
  rl = INT(RND * 10) + 1: m%(of, 8) = ABS(rl > 4) * 59 + ABS(rl > 7)
END IF
w = m%(of, 8): IF m%(of, 6) = -2 THEN RETURN
IF of = 0 THEN w2 = a%(m%(0, 8), 6): hit = 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
'
odds = 50 + 2 * (m%(of, 2) - m%(df, 2) - m%(of, 7) + m%(df, 7))
IF w > 0 THEN odds = odds + a%(w, 5) / 2
IF of = 0 THEN odds = odds + 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 df = 5 THEN PRINT " === Cyborg laughs and dodges!": GOTO Lp4
IF (rl < 5 OR rl < odds) 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
'
PRINT "...A fumble!": GOSUB Lp2: r = INT(RND * 100 + 1)
IF r < 41 OR w = 59 OR w = 60 THEN PRINT "    Recovered.": GOTO Lp4
'
IF r < 81 THEN
  a$ = m$(of) + " drops " + a$(w) + "!": GOSUB Lp0
  GOSUB WTRem: 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
'
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) - 2
  IF a%(w, 8) > 0 THEN PRINT " Weapon damaged!": GOTO Lp4
END IF
'
PRINT " Weapon broken!": GOSUB WTRem: 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
  GOSUB RollDice: up = ABS(rl > odds + wa%(w2))
  IF rl < wa%(w2) THEN
    IF ABS(ea) > INT(RND * 10) + 1 AND ae < a3 * a3 AND ae < 65 THEN
      ae = ae + 2: m = 0: GOSUB Pu2:
      a$ = a$ + "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)
a = 1: PRINT MID$(" ***  +++ ", ABS((df > 0)) * 5 + 1, 5);
IF rl > 5 THEN PRINT "A hit!": GOSUB Lp2: GOTO Damage0
'
Battle3:
PRINT "Well struck!": GOSUB Lp2: GOSUB RollDice
IF rl < 51 THEN a = 0: GOTO Damage0
r = 1.5: IF rl > 85 THEN r = 2
IF rl > 95 THEN r = 3
IF rl = 100 THEN r = m%(df, 1)
s = r * 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$ + "okay.": GOTO Lp10
Ms3:
a$ = a$ + "hurt.": GOTO Lp10
Ms4:
IF df = 4 THEN a$ = a$ + "severely dented.": GOTO Lp10
a$ = a$ + "beat and bloody.": GOTO Lp10
Ms5:
a$ = a$ + "gravely injured.": GOTO Lp10
Ms6:
a$ = a$ + "dying.": GOTO Lp10
'---------------------------------------------------------------------------
' Monster dies
'
Mdead:
IF df = 13 THEN
  a$ = a$ + "knocked out!": GOSUB Lp10
  m%(df, 5) = 0: m%(df, 13) = 0: r = 47: GOSUB Effect
  FOR m = 19 TO 20
     IF m%(m, 5) THEN PRINT m$(m); " joins you.": m%(m, 5) = ro: GOSUB Lp2
  NEXT: GOSUB Lp1: RETURN
END IF
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 df = 1 THEN a%(2, 7) = 2: a%(2, 8) = 8
IF df = 24 AND ro < 43 THEN m%(df, 5) = 48: m%(df, 3) = 5: m%(df, 0) = 0
Mdead2:
w = m%(df, 11): t(w) = t(w) - m%(df, 1): GOTO Lp10
END SUB

