'     THE WONDERFUL WORLD OF EAMON DELUXE
'           BY WONDERFUL FRANK
'
'   A COMPUTERIZED FANTASY ROLE-PLAYING SYSTEM
' BASED UPON THE APPLE II VERSION BY DONALD BROWN,
'    JOHN NELSON, TOM ZUCHOWSKI, & FRANK
'
'              BASE DUNGEON PROGRAM v3.1
'
' Redemption by Sam Ruby                  Update: 10 MAR 2005
'
' Converted to Eamon Deluxe in 1997 by Frank Black

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, 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 = 45: naf = 40: nm = 43: ne = 63: nd = 10: na = naf
adj1 = 49: adj2 = 65: adj3 = 30: adj4 = 54
'
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$(8, 2), c$(nc), d%(200), m$(nm), m%(nm, 15)
DIM SHARED r%(nr, 11), r$(nr), rb$(5, 1), sex$(2), sm$(3), t(4), wp%(na)
DIM SHARED wp$(5), gm$(5), bg$(3), cy$(5), mv$(2)
'---------------------------------------------------------------------------
'  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 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
'
'   PLAYER
'
CLOSE
OPEN "REDMPTN.DAT" FOR INPUT AS #1
INPUT #1, m$(0)
CLOSE

m%(0, 1) = 20: m%(0, 2) = 24: m%(0, 3) = 0: m%(0, 4) = 0
m%(0, 5) = 0: m%(0, 6) = 0: m%(0, 7) = 0: m%(0, 8) = 1
m%(0, 9) = 1: m%(0, 10) = 3

a%(0, 5) = 15: a%(0, 6) = 1: a%(0, 7) = 1: a%(0, 8) = 4

'
'    Set starting variable values
'
ro = 13: r2 = 13: r3 = 13: q$ = CHR$(34): d%(4) = 120: d%(1) = 1
sex$(0) = "Male": sex$(1) = "Female"
m%(6, 14) = -2: m%(8, 14) = -3: m%(10, 14) = -17: m%(16, 14) = -27
m%(17, 14) = -28: m%(20, 14) = -30: m%(30, 14) = -42: m%(31, 14) = -44
m%(32, 14) = -47: m%(34, 14) = -49: m%(39, 14) = -52: m%(42, 14) = -55
m%(42, 15) = 5
FOR a = 1 TO 8
   FOR a2 = 0 TO 2: READ bv$(a, a2): NEXT
NEXT

FOR a = 1 TO 3: READ sm$(a): NEXT
FOR a = 1 TO 5: READ wp$(a): NEXT
FOR a = 1 TO 3: READ bg$(a): NEXT
FOR a = 1 TO 5: READ cy$(a): NEXT
FOR a = 1 TO 2: READ mv$(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
END IF
a = INT(RND * 3) + 1: m$(2) = bg$(a): m%(2, 5) = 2 * a + 1
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.1)": 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
CHDIR "..": RUN "EAMONDX"
'
DATA 40,north,south,east,west,up,down,ne,nw,se,sw,flee,enter,drink,drop
DATA examine,get,light,open,put,read,ready,remove,use,wear,attack,ask,free
DATA give,heal,smile,talk,buy,sell,inventory,look,say,hints,save
DATA restore,quit
'
DATA punches at,kicks at,lunges at,stabs at,thrusts at,chops at,slashes at
DATA hacks at,slices at,leaps at,claws at,bites at,swoops down on,snaps at
DATA tears at,bites at,stomps on,swings his tail at,tears at,grapples with
DATA strikes at,pokes at,beats on,smacks

'
DATA growl,look,smile
DATA axe,missile weapon,club,spear,sword
'
DATA Bandit,Ruffian,Rogue
DATA Agroville,Kingscourt,Ironcastle,Shrine City,Tradetown
DATA Entering,Leaving

SUB Main

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

Main:
IF die = 1 THEN GOTO EndGame
COLOR 12: GOSUB Lp1
IF d%(3) > 0 THEN PRINT "You can't see!": GOSUB Lp4: GOTO Com1
'
IF ls = 0 THEN GOTO Main2A
a%(ls, 5) = a%(ls, 5) - 1: m = a%(ls, 5)
IF m = 0 THEN
  COLOR 2: PRINT "Your torch has gone out!": COLOR 12
  a%(ls, 6) = a%(ls, 6) - 1
  IF a%(ls, 6) > 0 THEN a%(ls, 5) = a%(ls, 7)
  ls = 0: lt = nl: GOTO Main0
END IF

Main1A:
IF m < 10 THEN
  PRINT "Your torch is almost out!": GOSUB Lp4: GOTO Main2A
END IF

Main1B:
IF m < 20 THEN PRINT "Your torch grows dim!": GOSUB Lp4

Main2A:
Main3A:
IF lt = 0 THEN PRINT "It's too dark to see.": GOSUB Lp4: GOTO Com1
'
' Give room name and description
'
Main3B:
a$ = "You are " + r$(ro)
IF ro = 10 AND (r3 = 10 OR r3 = 40) THEN
  a$ = "You are paddling across the Great Lake."
END IF
PRINT a$: GOSUB Lp4
IF r%(ro, 0) = 0 THEN
  r%(ro, 0) = 1: r = ro: GOSUB DiskRead
END IF
IF ro = 32 AND d%(18) = 0 THEN
  COLOR 3: PRINT q$; "Lords of Darkness, we call upon you to appear!"; q$
  COLOR 12: d%(18) = 1: GOSUB Lp4
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
IF d%(10) = 4 THEN
  d%(10) = 5: PRINT "Do you surrender?"; : GOSUB AF1
  IF s$ <> "y" THEN GOTO Main5A
  PRINT "You are tried for murder.  The next thing you know, there's a noose around your neck..."
  GOSUB Lp4: df = 0: m%(0, 13) = m%(0, 1): GOSUB Mstatus: GOTO EndGame
END IF
'
' 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 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
IF d%(11) = 1 THEN d%(11) = 2: r = 16: GOSUB Effect
IF d%(13) = 1 AND ro = 21 THEN d%(13) = 2: GOSUB Lp1: GOTO Ask1
'
' Get command
'
Com0:
GOSUB Lp1
IF d%(13) = 2 AND ro = 22 THEN
  d%(13) = 3: COLOR 2: r = 26: GOSUB Effect: COLOR 12
END IF
IF d%(18) = 1 THEN
  COLOR 0, 14: PRINT q$; "A S K  Y O U R  Q U E S T I O N."; q$;
  COLOR 12, 0: PRINT : GOSUB Lp4: d%(18) = 2
END IF
IF ro = 45 AND m%(21, 5) = ro AND a%(32, 4) = ro THEN
  COLOR 3: PRINT "The caravan collects the treasure.": COLOR 12
  a%(32, 4) = -22: GOSUB Lp4
END IF
IF ro = 35 AND m%(21, 5) = ro AND a%(32, 4) = -22 AND a%(5, 4) = ro THEN
  COLOR 3: PRINT "Shall the caravan load the treasure onto the boat?";
  GOSUB AF1: COLOR 12: GOSUB Lp1: IF s$ <> "y" THEN GOTO Com1
  a%(32, 4) = 1005: m%(21, 5) = 0: GOSUB EnemyCheck
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, 4)
   IF zz$ = " to " OR zz$ = " on " OR zz$ = " in " OR zz$ = " of " THEN
     s2$ = LTRIM$(RTRIM$(MID$(s$, a + 4)))
     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$ = " for " THEN
     s2$ = LTRIM$(RTRIM$(MID$(s$, a + 5)))
     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, 6)
   IF zz$ = " from " OR zz$ = " with " THEN
     s2$ = LTRIM$(RTRIM$(MID$(s$, a + 6)))
     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, 7)
   IF zz$ = " about " THEN
     s2$ = LTRIM$(RTRIM$(MID$(s$, a + 7)))
     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 Enter, Drink, Drop, Examine, ItemGet, Light, ItemOpen
ON c - 18 GOTO ItemPut, ItemRead, Ready, Remove, Use, Wear
ON c - 24 GOTO Attack, Ask, Free, Give, Heal, Smile, Talk
ON c - 31 GOTO Buy, Sell, Inventory, Look, Say, Hints
ON c - 37 GOTO GameSave, GameRestore, Quit
'---------------------------------------------------------------------------
'  Pick foes
'
Pfoe:
IF die = 1 THEN GOTO EndGame
IF t(1) <= 0 THEN t(1) = 0: GOTO Pfoe3
GOSUB Lp1: m = 0

Pfoe0:
m = m + 1
IF m%(m, 5) <> ro THEN GOTO Pfoe2A
IF m%(m, 11) = 2 THEN GOTO Pfoe2A
'
'  Will monster flee?
'
IF m = 41 AND m%(m, 3) = 14 THEN
  m%(m, 5) = 0: GOSUB EnemyCheck
  PRINT "The kobold horde flees!": GOSUB Lp4: GOTO Pfoe2A
END IF
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:
IF d%(10) = 1 THEN
  d%(10) = 2: PRINT q$; "Alarm, alarm!  Help, help!"; q$: GOSUB Lp4
END IF
IF d%(10) = 3 THEN
  IF ro > 12 AND ro < 18 THEN m%(43, 5) = ro: m$(43) = "Militia Fighter"
  IF ro > 17 AND ro < 23 THEN m%(43, 5) = ro: m$(43) = "Royal City Guard"
  IF ro > 22 AND ro < 28 THEN m%(43, 5) = ro: m$(43) = "Castle Soldier"
  IF ro > 27 AND ro < 33 THEN m%(43, 5) = ro: m$(43) = "Fanatic"
  IF ro > 32 AND ro < 38 THEN m%(43, 5) = ro: m$(43) = "Police Officer"
  d%(10) = 4: GOSUB EnemyCheck
END IF
IF a%(9, 8) > 0 THEN
  a%(9, 8) = a%(9, 8) - 1
  IF a%(9, 8) < 1 THEN PRINT "The cloth dries out!": GOSUB Lp4
END IF
IF d%(3) > 0 THEN
  d%(3) = d%(3) - 1
  IF d%(3) < 1 THEN lt = 1
END IF
GOTO Main
'---------------------------------------------------------------------------
' **** Movement commands ****
'
' **** Directions ****
'
Move:
r2 = r%(ro, c)
IF t(1) > 0 THEN PRINT "You'll have to run for it!": GOTO Main0
IF lt = 0 THEN GOTO Main0

MoveCheck:
IF r2 > 1000 THEN GOTO Move1
IF r2 > 0 AND r2 <= nr THEN GOTO Move2
'
IF m%(1, 5) = ro AND r2 < 0 AND r2 > -34 THEN
  PRINT "You'll have to pay the ferryman.": GOTO Main0
END IF
IF r2 < 0 AND r2 > -34 THEN
  PRINT "You'll have to take a ferry."
  m%(1, 5) = ro: GOSUB EnemyCheck: GOTO Main0
END IF
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, 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:
m = 0: p = 0
IF r2 = 1 AND ro = 16 THEN m = 2: p = 1
IF r2 = 16 AND ro = 1 THEN m = 1: p = 1
IF r2 = 18 AND ro = 7 THEN m = 1: p = 2
IF r2 = 7 AND ro = 18 THEN m = 2: p = 2
IF r2 = 23 AND ro = 5 THEN m = 1: p = 3
IF r2 = 5 AND ro = 23 THEN m = 2: p = 3
IF r2 = 3 AND ro = 28 THEN m = 2: p = 4
IF r2 = 28 AND ro = 3 THEN m = 1: p = 4
IF ro = 33 AND r2 < 11 THEN m = 2: p = 5
IF r2 = 33 AND ro < 33 THEN m = 1: p = 5
IF m > 0 AND p > 0 THEN PRINT mv$(m); " "; cy$(p); ".": GOSUB Lp4
IF ro = 10 AND r2 = 10 AND a%(16, 4) <> -1 THEN
  PRINT "You can't swim the whole lake!": GOTO Main0
END IF
IF r2 = ro THEN d%(2) = d%(2) + 1
IF r2 <> ro THEN d%(2) = 0
IF r2 = 22 AND d%(5) = 0 AND m%(14, 5) = ro THEN
  PRINT "The guards block the doors and prevent you from entering.": GOTO Main0
END IF
IF r2 = 22 AND d%(5) > 0 THEN
  PRINT "The guards open the doors for you and move out of the way."
  d%(5) = 0: GOSUB Lp4
END IF
IF r2 = 27 AND ro = 26 AND d%(16) = 0 THEN
  PRINT "The soldiers won't let you enter.": GOTO Lp12
END IF
IF r2 = 45 AND d%(9) = 0 THEN
  d%(9) = 1: m%(42, 5) = ro: GOSUB EnemyCheck: GOTO Main
END IF
IF ls > 0 AND ls <= na THEN IF a%(ls, 4) <> -1 THEN ls = 0
r3 = ro: ro = r2: GOSUB MoveMons
IF m%(1, 5) = ro THEN m%(1, 5) = 0
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 torch?";
  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 m%(43, 5) = ro THEN PRINT "You're surrounded!": 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
'
' ENTER command
'
Enter:
GOSUB CheckSub: wh = ro: ha = ro: em = ro
GOSUB Asearch2: IF f = 0 THEN PRINT "That's not here.": GOTO Main0
IF a > 5 THEN s$ = "that": GOTO Err3
r2 = a%(a, 8): GOTO MoveCheck
'---------------------------------------------------------------------------
'  Artifact manipulation commands
'
' **** Drink command ****
'
Drink:
GOSUB CheckSub: GOSUB Asearch0: IF f = 0 THEN GOTO Err3
m = a%(a, 2): IF m <> 6 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
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
'
Drop2:
wt = wt - a%(a, 3): a%(a, 4) = ro
IF a = d%(1) THEN
  d%(1) = 0: m%(0, 6) = 10: m%(0, 8) = 1: m%(0, 9) = 1: m%(0, 10) = 3
END IF
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:
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
IF a = 37 THEN a%(38, 4) = ro: a%(39, 4) = ro: a$(a) = "lever"
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:
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 a = 30 AND d%(6) = 0 THEN
  d%(6) = 1: m%(38, 5) = ro: GOSUB EnemyCheck: GOTO Main
END IF
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 OR a = 30 THEN GOTO ItemGet2A
     GOSUB ItemGet3
   END IF
ItemGet2A:
NEXT: GOTO Pfoe
'
ItemGet3:
a2 = a%(a, 2)
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 a = 30 AND a%(36, 4) <> ro THEN
  a%(35, 4) = ro: a%(36, 4) = ro
  GOSUB Lp4: PRINT "What's this? ......"
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 torch.": GOTO Lp12
IF a = ls THEN PRINT "Extinguish the torch?"; : 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 = 38 THEN PRINT "How?": GOTO Main0
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
IF a%(a, 6) = 1 THEN PRINT "It's already open.": GOTO Lp12
'
a%(a, 5) = 0: a%(a, 6) = 1
GOSUB Pu0: PRINT a$; "opened.": GOSUB Lp4
m = INT(RND * 10) + 1 + a%(a, 1)
PRINT "You find"; : COLOR 2: PRINT m; : COLOR 3: PRINT "gold pieces inside!"
gold = gold + m: GOTO Lp12
'
' ** 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 a = 33 AND a%(a, 7) <> 0 THEN
  PRINT "You'll have to dig your way to it.": GOTO Lp12
END IF
'
IF k > 0 AND k <= naf THEN
  IF a%(k, 4) <> -1 AND a%(k, 4) <> ro THEN : PRINT "It's locked.": GOTO Lp12
  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 AND a <> 33 THEN PRINT "It won't open.": GOTO Lp12
'
a$ = "You've opened the " + a$(a) + "."
DoorOpen1:
IF a = 36 THEN m%(39, 5) = ro: GOSUB EnemyCheck
a%(a, 6) = 0: a%(a, 7) = 0: GOTO Lp9
'
' **** Put command ****
'
ItemPut:
IF lt = 0 THEN GOTO Main
IF t(1) > 0 THEN PRINT "You can't do that right now.": GOTO Main0
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
  wh = -999: ha = wh = em = wh: GOSUB Asearch2
  IF f = 0 THEN GOTO Err1
END IF
IF a = m OR (m <> 40 AND m <> 22) THEN
  PRINT "You don't need to do that.": GOTO Main0
END IF
'  CRYSTAL
IF a = 39 AND m = 40 THEN
  a%(m, 4) = 1039: a = m: GOSUB WTRem: r = 54: GOSUB Effect: GOTO Main
END IF
'  ANTIDOTE
IF a <> 9 OR m <> 22 THEN
  PRINT "There's no reason to do that.": GOTO Main0
END IF
PRINT "You apply the antidote to the cloth.": GOSUB Lp4
a%(m, 6) = a%(m, 6) - 1: a%(a, 8) = a%(a, 8) + 10
IF a%(m, 6) < 1 THEN
  PRINT "That's the last of it.": GOSUB Lp4
  a = m: GOSUB WTRem: a%(a, 4) = 0
END IF
GOTO Pfoe
'
' **** Read command ****
'
ItemRead:
IF lt = 0 THEN GOTO Main
GOSUB CheckSub: wh = ro: ha = -1: em = ro: GOSUB Asearch2
IF f = 0 THEN GOTO Err1
IF a <> 35 THEN s$ = "that": GOTO Err3
COLOR 2
PRINT "        HE WHO OPENS THIS GATE SHALL UNLEASH A VILE AND CURSED THING!"
COLOR 3: GOTO Lp12
'
' **** 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
m%(0, 8) = a%(a, 6): m%(0, 9) = a%(a, 7): m%(0, 10) = a%(a, 8)
d%(1) = 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 + 400: GOSUB DiskRead
GOTO Pfoe
'
' **** Use command ****
'
Use:
IF lt = 0 THEN GOTO Main
GOSUB CheckSub: GOSUB Asearch0: IF f = 0 THEN GOTO Err1
IF a = 22 THEN PRINT "Try to PUT it on something.": GOTO Main0
IF a%(a, 2) <> 0 THEN GOTO Use1
'
'     SHOVEL
'
IF a%(a, 5) = 1 THEN
  PRINT "You dig.": GOSUB Lp4
  IF a%(33, 4) = ro THEN
    PRINT "You've cleared away the earth that blocked the door."
    a%(33, 7) = 0: GOTO Lp12
  END IF
  GOTO Pfoe
END IF
'
'     MINE
'
IF a%(a, 5) = 2 THEN
  IF ro <> 42 THEN PRINT "There's nothing to mine here.": GOTO Lp12
  PRINT "Mining...": GOSUB Lp4: FOR m# = 1 TO dly# * 2: NEXT
  a%(15, 8) = a%(15, 8) + 1
  IF a%(15, 8) = 3 THEN
    PRINT "Maybe you should try that shaft after you're done mining."
    a%(28, 4) = ro: GOSUB Lp4: FOR m# = 1 TO dly# * 2: NEXT
    PRINT "You found something!": GOTO Lp12
  END IF
  m%(40, 5) = ro: m%(40, 0) = 0: GOSUB EnemyCheck
  PRINT "Nothing found yet.": GOTO Main0
END IF
'
'     CANOE
'
IF a%(a, 5) = 3 THEN
  IF ro <> 10 THEN s$ = "that here": GOTO Err3
  PRINT "You're in the canoe.": GOTO Lp12
END IF
'
'     MAPS
'
IF a%(a, 5) = 4 THEN
  IF ro <> a%(a, 6) THEN PRINT "It doesn't help you here.": GOTO Main0
  IF d%(2) = 0 THEN PRINT "You have to go further into the area first.": GOTO Main0
  IF d%(2) = 1 THEN PRINT "Keep going.": GOTO Main0
  a%(a%(a, 7), 4) = ro
  PRINT "You find what you have been looking for.": GOTO Lp12
END IF
'
'     LEVER
'
IF a%(a, 5) = 5 THEN
  IF a%(40, 4) = 1039 AND a%(27, 4) = 1039 THEN
    a%(27, 4) = ro: r = 53: GOSUB Effect: GOTO Pfoe
  END IF
  PRINT "Nothing happens.": GOTO Lp12
END IF
Use1:
PRINT "Try another command.": GOTO Lp12
'
' **** 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, 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
'
'  ASK command
'
Ask:
GOSUB CheckSub:  GOSUB Msearch: IF f = 0 THEN GOTO Err4
a$ = "For/about what": GOSUB CheckSub2
s$ = s2$: GOSUB Synonym
IF m = 13 AND d%(13) <> 3 THEN
  PRINT q$; "I don't casually give out privileged information!"; q$
  GOTO Lp12
END IF
'
IF s$ = "blog" THEN GOTO Ask2
'
IF m = 18 AND s$ = "sir blackstone" THEN
  PRINT "The guards see that you are a worker and let you pass."
  d%(16) = 1: GOTO Lp12
END IF
IF m = 19 AND s$ = "foreman" THEN
  m%(20, 5) = ro: GOSUB EnemyCheck: GOTO Pfoe
END IF
IF m = 12 AND s$ = "instructions" THEN
  r = 24: GOSUB Effect: GOSUB AskDrop: GOTO Pfoe
END IF
IF m = 16 AND s$ = "special helm" AND a%(8, 4) = -17 THEN
  a%(8, 4) = ro: GOTO Pfoe
END IF
'
IF m = 24 AND LEFT$(s$, 4) = "heal" THEN
  m = 0: df = m: a$ = "The Monk sees that you are ": GOSUB Mstatus1
  IF m%(0, 13) = 0 THEN GOTO Pfoe
  p = m%(0, 13)
  PRINT "Healing will require a donation of "; LTRIM$(RTRIM$(STR$(p)));
  PRINT " gold pieces.": GOSUB Lp4: PRINT "Will you pay?"; : GOSUB AF1
  IF s$ = "n" THEN GOTO Pfoe
  IF gold = 0 THEN PRINT "You don't have any money for healing.": GOTO Lp12
  IF gold < p THEN p = gold
  gold = gold - p: m%(0, 13) = m%(0, 13) - p
  PRINT "The process begins...": GOSUB Lp4
  IF m%(0, 13) > 0 THEN
    PRINT "You didn't have enough money to heal completely.": GOSUB Lp4
  END IF
  IF m%(0, 13) = 0 THEN PRINT m$(0); " is in perfect health!": GOTO Lp12
  GOTO Pfoe
END IF
'
sl = LEN(s$)
IF m = 24 AND s$ = LEFT$("cleric of light", sl) THEN
  PRINT "He takes you to a chamber to the southeast.": GOSUB Lp4
  r2 = 30: GOTO Move2
END IF
IF m = 25 AND s$ = LEFT$("blessing", sl) THEN
  PRINT "He says that it will cost 25 gold pieces.": GOSUB Lp4
  IF gold < 25 THEN PRINT "You can't afford it.": GOTO Lp12
  PRINT "Will you pay?"; : GOSUB AF1: IF s$ = "n" THEN GOTO Pfoe
  FOR a = 11 TO 13
     IF a%(a, 4) = -1 THEN a%(a, 2) = 3
  NEXT
  gold = gold - 25: m%(0, 14) = 1: a%(0, 2) = 3
  r = 61: GOSUB Effect: GOTO Pfoe
END IF
IF m = 14 AND s$ = "audience" THEN
  IF d%(12) > 0 THEN GOTO Ask1
  r = 19: GOSUB Effect
  a$ = "What name(s) do you give": s2$ = "": GOSUB CheckSub2
  IF s2$ <> "midnight oilers" THEN r = 63: GOSUB Effect: GOTO Pfoe
  d%(12) = 1
Ask1:
  d%(5) = 1: r = 62: GOSUB Effect: COLOR 12: GOTO Com0
END IF
IF m = 34 AND s$ = "eagle" THEN
  r = 50: GOSUB Effect: r%(38, 5) = 39
  IF RIGHT$(r$(38), 4) <> "U,D)" THEN
    r$(38) = LEFT$(r$(38), LEN(r$(38)) - 2) + "U,D)"
  END IF
  GOTO Main
END IF
IF m = 37 AND s$ = LEFT$("eggshells", sl) THEN
  a%(25, 4) = 8: a%(25, 3) = 10: a%(1, 4) = 0: a%(19, 4) = 0
  r = 51: GOSUB Effect: r2 = 8: GOTO Move2
END IF
IF m = 13 AND s$ = "logres" THEN
  r = 25: GOSUB Effect: GOSUB AskDrop: GOTO Pfoe
END IF
IF m = 34 OR m = 13 THEN
  PRINT m$(m); " has no relevant information about that.": GOTO Lp12
END IF
IF m = 27 THEN
  PRINT "You only get one question.  I think you'd better ask about something else..."
  GOSUB Lp4: COLOR 12: GOTO Com0
END IF
'
Ask1A:
s$ = " shrugs.": IF m%(m, 3) > 1 THEN s$ = "s shrug."
PRINT m$(m); s$: GOTO Lp12
'
'  ASK about BLOG
'
Ask2:
IF m = 6 THEN
  IF a%(6, 4) <> -7 THEN PRINT "He has nothing else you could use.": GOTO Lp12
  PRINT "He gives you some leather armour and wishes you luck."
  a%(6, 4) = ro: GOTO Lp12
END IF
IF m = 7 OR m = 9 THEN
  IF m = 9 THEN d%(11) = 1
  GOSUB AskDrop: GOTO Pfoe
END IF
IF m = 15 THEN
  r = 21: GOSUB Effect: r = 22: GOSUB Effect1
  r = 23: GOSUB Effect: GOTO Pfoe
END IF
IF m = 22 THEN
  r = 32: GOSUB Effect: r = 33: GOSUB Effect
  r = 34: GOSUB Effect1: r = 35: GOSUB Effect: GOTO Pfoe
END IF
IF m = 26 THEN
  r = 36: GOSUB Effect: r = 37: GOSUB Effect: r = 38: GOSUB Effect1
  r = 39: GOSUB Effect1: r = 40: GOSUB Effect1: r = 41: GOSUB Effect
  GOTO Pfoe
END IF
IF m = 32 THEN r = 20: GOSUB Effect: GOTO Pfoe
IF m <> 27 THEN GOTO Ask1A
a$ = q$ + "Demon:  Where is the lair of the Green Dragon called Blog?" + q$
FOR a = 1 TO LEN(a$)
   PRINT MID$(a$, a, 1);
   FOR m# = 1 TO dly# / 4: NEXT
NEXT
PRINT : GOSUB Lp4: GOSUB Lp6
a$ = q$ + "C A S T L E.....L O G R E S" + q$
PRINT SPC(24); : COLOR 0, 2
FOR a = 1 TO LEN(a$)
   PRINT MID$(a$, a, 1);
   FOR m# = 1 TO dly# / 2: NEXT
NEXT
COLOR 3, 0: PRINT : GOSUB Lp4
PRINT "The demon disappears and the pit returns to normal."
m%(27, 5) = 0: GOSUB EnemyCheck: GOTO Lp12
'
AskDrop:
f = 0
FOR a = 1 TO na
   IF a%(a, 4) = -m - 1 THEN a%(a, 4) = ro: f = 1
NEXT
IF f = 0 THEN PRINT "He has nothing more to give you.": GOSUB Lp4
RETURN
'
' TALK COMMAND
'
Talk:
GOSUB CheckSub:  GOSUB Msearch: IF f = 0 THEN GOTO Err4
IF m = 42 THEN
  r = 55: GOSUB Effect: r = 56: COLOR 2: GOSUB Effect: COLOR 3
  r = 57: GOSUB Effect: COLOR 2
  PRINT q$; "NAY, FOOL, IT IS I WHO SENTENCE YOU!"; q$: COLOR 3: GOTO Lp12
END IF
IF m%(m, 11) = 1 AND m <> 39 THEN
  PRINT "Your words are answered with blows!": GOTO Lp12
END IF
IF m = 22 THEN
  PRINT q$; "Very well, you shall take some men and go to the quarry.  Is that all?"; q$
  COLOR 12: GOSUB Lp4: GOTO Com0
END IF
IF m = 29 THEN
  PRINT "The supplier thinks you might be interested in TORCHES or a CANOE."
  GOTO Lp12
END IF
IF m%(m, 14) > -1 THEN PRINT "You exchange greetings.": GOTO Lp12
x = ABS(m%(m, 14)): y = x
IF m = 10 OR m = 17 OR m = 31 THEN
  PRINT q$; "I've got something an adventurer like you might be interested in."; q$
  GOSUB Lp4
END IF
IF m = 8 THEN
  r = 3: GOSUB Effect
  FOR a = 4 TO 7: r = a: GOSUB Effect1: NEXT
  GOSUB Lp1: r = 8: GOSUB Effect: GOTO Talk1
END IF
IF m = 17 THEN y = 29
IF m = 30 THEN y = 43
IF m = 31 THEN y = 46
IF m = 32 THEN y = 48
IF m = 17 OR m = 30 OR m = 32 THEN
  FOR a = x TO y: r = a: GOSUB Effect: NEXT: GOSUB Lp1: GOTO Talk1
END IF
FOR a = x TO y: r = a: GOSUB Effect1: NEXT: GOSUB Lp1
Talk1:
IF m = 8 AND d%(7) = 0 THEN
  PRINT "Do you offer to help?"; : GOSUB AF1: IF s$ = "n" THEN GOTO Pfoe
  r = 9: GOSUB Effect: r = 10: GOSUB Effect1: r = 11: GOSUB Effect
  r = 12: GOSUB Effect1: r = 13: GOSUB Effect
  r = 14: GOSUB Effect: r = 15: GOSUB Effect
  PRINT "He gives you 10 gold pieces.": GOSUB Lp4
  PRINT q$; "Oh, ask the leather worker for help too."; q$
  gold = gold + 10: d%(7) = 1: GOTO Lp12
END IF
IF m = 20 THEN
  PRINT "Do you take the job?"; : GOSUB AF1: IF s$ = "n" THEN GOTO Pfoe
  PRINT "You start to work...": GOSUB Lp4
  FOR a# = 1 TO dly# * 2: NEXT
  PRINT "Uh-oh, an accident!": GOSUB Lp4
  d2 = 2 + INT(RND * 5): df = 0: GOSUB Damage1: GOSUB Lp6
  PRINT "You work for several days.  On the fifth day...": GOSUB Lp4
  r = 31: GOSUB Effect: gold = gold + 25: m%(20, 14) = 0: GOTO Main
END IF
GOTO Main
'
'  BUY COMMAND
'
Buy:
IF ro = 19 THEN
  PRINT "The only thing you can buy here are those lousy commemorative coins."
  GOTO Main0
END IF
IF ro = 29 OR ro = 30 THEN PRINT "ASK for it.": GOTO Main0
m = 0: f = 0
IF ro = 35 THEN m = 30: GOTO Buy1
FOR a = 1 TO nm
   IF m%(a, 5) = ro THEN m = a: a = nm
NEXT
IF m = 0 THEN PRINT "There's no one here to buy from.": GOTO Main0
IF m <> 6 AND m <> 10 AND m <> 16 AND m <> 17 AND m <> 29 AND m <> 30 AND m <> 31 THEN
  PRINT "He's not selling anything.": GOTO Main0
END IF
Buy1:
PRINT "Right now he has:": GOSUB Lp2
FOR a = 1 TO na
   IF a%(a, 4) = -m - 1 AND a <> 8 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.": 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 = -m - 1: ha = wh: em = wh: GOSUB Asearch2
IF f = 0 THEN PRINT "He doesn't have that.": GOTO Lp12
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): a%(a, 1) = INT(a%(a, 1) / 3)
GOSUB Lp1: PRINT q$; "Sold!"; q$: GOSUB Lp4: GOTO Buy
'
'  SELL COMMAND
'
Sell:
GOSUB CheckSub: GOSUB Asearch
IF f = 0 THEN PRINT "You don't have it.": GOTO Main0
IF a%(a, 1) = 0 OR m%(28, 5) <> ro THEN
  PRINT "You can't find a buyer.": GOTO Main0
END IF
f = INT(RND * 5) - 2: f = f / 10: d = 0
IF f <> 0 THEN
  r = INT(ABS(f) * a%(a, 1))
  IF r > 0 THEN d = INT(RND * r) + 1
  IF f < 0 THEN d = -d
END IF
m = a%(a, 1) - d
PRINT "You find one merchant who offers you"; m; "gold pieces.": GOSUB Lp4
PRINT "Sell the "; a$(a); "?"; : GOSUB AF1: IF s$ <> "y" THEN GOTO Pfoe
GOSUB WTRem: a%(a, 4) = 0: gold = gold + m
IF a = d%(1) THEN
  d%(1) = 0: m%(0, 6) = 10: m%(0, 8) = 1: m%(0, 9) = 1: m%(0, 10) = 3
END IF
PRINT "Sold!": GOTO Lp12
'
'  **** Attack command ****
'
Attack:
IF d%(1) < 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
END IF
'
of = 0: df = m: GOSUB Battle: IF die = 1 THEN GOTO EndGame
'
IF m%(df, 11) > 1 THEN
  m%(df, 11) = 1: GOSUB EnemyCheck
  IF d%(10) > 0 OR df = 1 OR df > 33 THEN GOTO Pfoe
  d%(10) = 1
  PRINT q$; "Alarm, alarm!  Help, help!"; q$: GOSUB Lp4
  IF ro > 12 AND ro < 18 THEN m%(43, 5) = ro: m$(43) = "Militia Fighter"
  IF ro > 17 AND ro < 23 THEN m%(43, 5) = ro: m$(43) = "Royal City Guard"
  IF ro > 22 AND ro < 28 THEN m%(43, 5) = ro: m$(43) = "Castle Soldier"
  IF ro > 27 AND ro < 33 THEN m%(43, 5) = ro: m$(43) = "Fanatic"
  IF ro > 32 AND ro < 38 THEN m%(43, 5) = ro: m$(43) = "Police Officer"
  GOSUB EnemyCheck: GOTO Main
END IF
'
GOTO Pfoe
'
'  Attack 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 m <> 4 AND m <> 8 THEN
  PRINT "Wanton destruction of property is no way to express yourself!"
  GOTO Main0
END IF
IF a%(a, k) < 100 THEN PRINT "Nothing happens.": GOTO Lp12
'
w = d%(1): 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
PRINT "Wham!  You hit the "; a$(a); "!": GOSUB Lp4
a%(a, x) = a%(a, x) - d2
'
IF a%(a, x) < 100 THEN
  a%(a, x) = 1 - ABS(m = 8): a%(a, k) = 0
  IF a = 31 THEN a%(a, 6) = 0
  PRINT "It shatters!  You can now force it open!": GOTO Lp12
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 = 1 THEN
  IF k > 1 THEN gold = gold + k - 1
  FOR a = 1 TO 10: r%(ro, a) = ABS(r%(ro, a)): NEXT
  m%(1, 5) = 0: GOSUB EnemyCheck: r = 1: GOSUB Effect: GOTO Pfoe
END IF
PRINT q$; "Thanks."; q$: GOTO Lp12
'
' Give an item
'
Give1:
a$ = "You give ": IF a <> 23 THEN a$ = a$ + "the "
a$ = a$ + a$(a) + " to " + m$(m) + "...": GOSUB Lp10
d%(8) = 0
'
IF m = 12 AND a = 27 THEN
  PRINT q$; "Wonderful!  I shall send word to the King.  Now go to the court."; q$
  d%(13) = 1: d%(8) = 1
END IF
IF m = 8 AND a = 23 THEN m%(21, 5) = ro: d%(8) = 1
IF m = 22 AND a = 25 THEN
  PRINT q$; "Well done, well done indeed!  Here is the weapon you have earned."; q$
  a%(13, 4) = ro: d%(8) = 1
END IF
IF m = 26 AND a = 26 THEN
  PRINT q$; "You have done the Servents of Darkness a great service.  Follow us."; q$
  GOSUB Lp4: PRINT "They pass through a curtain to the southwest."
  m%(m, 5) = 32: r%(ro, 10) = 32: d%(8) = 1
END IF
'
IF d%(8) = 0 THEN PRINT "He doesn't want it.": GOTO Main0
GOSUB WTRem: a%(a, 4) = -m - 1: IF a = d%(1) THEN d%(1) = 0
GOSUB EnemyCheck: GOSUB Lp4: 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";
PRINT " "; sm$(m%(m, 11)); : IF m%(m, 3) = 1 THEN PRINT "s";
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 = d%(1) 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
     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 lt = 0 THEN GOTO Main
r = ro: GOSUB DiskRead: GOTO Pfoe
'
' **** Say command ****
'
Say:
GOSUB CheckSub: s$ = LTRIM$(RTRIM$(LEFT$(s$, 60)))
s$ = UCASE$(LEFT$(s$, 1)) + LCASE$(MID$(s$, 2))
a$ = "Okay, " + q$ + LEFT$(s$, 60) + q$ + ".": GOSUB Lp10
IF s$ = "Bard" AND m%(11, 5) = ro THEN r = 18: GOSUB Effect
GOTO Pfoe
'
' **** Heal spell ****
'
Heal:
IF d%(4) < 20 THEN PRINT "You've exhausted your magical power.": GOTO Main0
PRINT m$(0); " tries to cast a heal spell...": GOSUB Lp4
GOSUB RollDice
IF rl >= d%(4) THEN PRINT "...but doesn't succeed this time.": GOTO Lp12
m%(0, 13) = 0: d%(4) = d%(4) * .6
PRINT "...and succeeds!": GOSUB Lp4
PRINT m$(0); " is in perfect health.": GOTO Lp12

' Hints
'------
Hints:
PRINT "Your question?": GOSUB Lp4
PRINT "    1- "; h$(1): GOSUB Lp2
a = 1: m = 1: IF nh > 1 THEN a = 16: m = 26
IF a > 1 THEN
  FOR r = a TO m
     IF r - (a - 2) < 10 THEN PRINT " ";
     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 = 0 TO na
   FOR m = 0 TO 8: PRINT #2, a%(a, m): NEXT
NEXT
FOR m = 0 TO nm
   FOR a = 0 TO 15: PRINT #2, m%(m, a): NEXT
NEXT
FOR r = 1 TO nr
   FOR m = 0 TO 11: PRINT #2, r%(r, m): NEXT
NEXT
FOR a = 1 TO 4: PRINT #2, t(a): NEXT
FOR a = 0 TO 200: PRINT #2, d%(a): NEXT
PRINT #2, ac, ae, ar, bank, ch, die, ea, gold, ls, lt, nl, r3, ro, sex, sh
PRINT #2, Speed, wt, r%(38, 5)
PRINT #2, a$(37)
PRINT #2, m$(43)
PRINT #2, m$(2)
PRINT #2, r$(38)
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 = 0 TO na
   FOR m = 0 TO 8: INPUT #2, a%(a, m): NEXT
NEXT
FOR m = 0 TO nm
   FOR a = 0 TO 15: INPUT #2, m%(m, a): NEXT
NEXT
FOR r = 1 TO nr
   FOR m = 0 TO 11: INPUT #2, r%(r, m): NEXT
NEXT
FOR a = 1 TO 4: INPUT #2, t(a): NEXT
FOR a = 0 TO 200: INPUT #2, d%(a): NEXT
INPUT #2, ac, ae, ar, bank, ch, die, ea, gold, ls, lt, nl, r3, ro, sex, sh
INPUT #2, Speed, wt, r%(38, 5)
INPUT #2, a$(37), m$(43), m$(2)
LINE INPUT #2, r$(38)
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
  IF a%(32, 4) <> 1005 THEN
    r = 58: GOSUB Effect: die = 1: GOSUB Lp6: GOTO Dead
  END IF
  FOR x = 59 TO 60: r = x: GOSUB Effect: NEXT
  PRINT q$; "MOUNT COLLAPSO ERUPTED!"; q$: GOSUB Lp4
  COLOR 0, 2: PRINT SPC(37); "THE END"; SPC(36); : COLOR 3, 0: PRINT
  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
'
Effect1:
GET #13, r + adj4, DS: a$ = RTRIM$(DS.TEXT): GOTO Lp0
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
'----------------------------------------------------------------------------
'
' 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)), UCASE$(c$(12)): PRINT '
PRINT "Artifact manipulation:"
FOR c = 13 TO 24: PRINT UCASE$(c$(c)), : NEXT: PRINT : PRINT
PRINT "Interactive:"
FOR c = 25 TO 33: PRINT UCASE$(c$(c)), : NEXT: PRINT : PRINT
PRINT "Miscelaneous:"
FOR c = 34 TO nc: PRINT UCASE$(c$(c)), : NEXT: PRINT : PRINT
COLOR 2: PRINT "New commands:  TALK, ASK, BUY, SELL, ENTER": COLOR 12
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: sy1$ = ""
IF ro = 17 OR ro = 10 THEN sy$ = "map of lake": sy = 17: GOTO Synonym1
IF ro = 24 OR ro = 12 THEN sy$ = "map of hills": sy = 18: GOTO Synonym1
IF ro = 36 OR ro = 9 THEN sy$ = "map of forest": sy = 19: GOTO Synonym1
IF ro = 11 THEN sy$ = "map of swamp": sy = 20: GOTO Synonym1
IF ro = 23 THEN sy$ = "helm": sy = 8: GOTO Synonym1
IF ro = 29 THEN sy$ = "treatment": sy1$ = "heal": GOTO Synonym2
IF ro = 26 THEN sy$ = "blackstone": sy1$ = "sir blackstone": GOTO Synonym2
IF ro = 38 THEN sy$ = "great eagle": sy1$ = "eagle": GOTO Synonym2
IF ro = 21 THEN sy$ = "king": sy1$ = "audience": GOTO Synonym2
IF ro = 19 THEN sy$ = "castle logres": sy1$ = "logres": GOTO Synonym2
GOSUB Synonym1: RETURN
Synonym1:
IF LEFT$(sy$, sl) = s$ OR RIGHT$(sy$, sl) = s$ THEN s$ = LCASE$(a$(sy))
RETURN
Synonym2:
IF LEFT$(sy$, sl) = s$ OR RIGHT$(sy$, sl) = s$ THEN s$ = sy1$
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
'---------------------------------------------------------------------------
'  Combat routine
'
Battle:
'
Battle0:
'
'  DRAGON BREATH
'
IF of = 42 AND m%(of, 15) > 0 AND d%(3) = 0 THEN
  d2 = 0: PRINT "Blog exhales a poisonous cloud!": GOSUB Lp4
  IF a%(8, 4) <> -999 THEN
    PRINT "The gas burns your eyes!  "; m$(0); " is blinded!"
    GOSUB Lp4: d%(3) = 10
  END IF
  IF a%(8, 4) = -999 THEN PRINT "The helm protects your eyes!": GOSUB Lp4
  IF a%(9, 4) <> -999 OR a%(9, 8) = 0 THEN
    PRINT "The gas burns your throat!  You are choking on poison!"
    d2 = 8: GOSUB Lp4
  END IF
  IF d2 = 0 THEN
    m%(of, 15) = m%(of, 15) - 1
    PRINT "The cloth filters out the poison!": GOTO Lp4
  END IF
  m%(df, 13) = m%(df, 13) + d2: GOTO Mstatus
END IF
'
'  Compute odds to hit
'
odds = 50 + 2 * (m%(of, 2) - m%(df, 2) - m%(df, 7) + m%(df, 7))
IF of = 0 THEN odds = odds + a%(d%(1), 5)
'
a = m%(of, 8)
a$ = m$(of) + " " + bv$(a, INT(RND * 3)) + " " + m$(df) + "..."
GOSUB Lp0: GOSUB RollDice
IF rl < odds THEN hit = 1: GOTO Battle1
IF RND > .5 THEN s$ = "dodged!": GOTO Battle00
IF m%(df, 8) = 2 OR m%(df, 8) = 3 OR m%(df, 8) = 8 THEN
  IF m%(of, 8) = 2 OR m%(of, 8) = 3 OR m%(of, 8) = 8 THEN
    s$ = "parried!": GOTO Battle00
  END IF
END IF
s$ = "warded off!"
Battle00:
PRINT " --- "; s$: GOTO Lp4
'
'
Battle1:
d = m%(of, 9): s = m%(of, 10)
PRINT " --- ";
IF df = 39 THEN
  IF a%(d%(1), 2) <> 3 THEN PRINT "your weapon does no damage!": GOTO Lp4
  PRINT "Your blessed weapon strikes home!": GOSUB Lp4
END IF
IF of = 39 THEN
  PRINT "and drains "; m$(0); "'s lifeforce!": GOSUB Lp4
  d2 = INT(RND * 5) + 1: GOTO Damage1
END IF
GOSUB Lp2
d2 = 0
FOR d3 = 1 TO d
   d2 = d2 + INT(RND * s) + 1
NEXT
d2 = d2 - m%(df, 7)
IF d2 < 0 THEN
  IF m%(df, 8) < 4 OR m%(df, 8) = 6 THEN
    PRINT "blow bounces off armour!": GOTO Lp4
  END IF
  PRINT "natural armour absorbs the blow!": GOTO Lp4
  IF d2 + m%(df, 13) >= m%(df, 1) THEN PRINT "a mortal blow!": GOSUB Lp4
END IF
'
Damage1:
'---------------------------------------------------------------------------
' Add damage/report monster's health
'
Mstatus:
a$ = "": IF m%(df, 3) > 1 THEN a$ = a$ + "The "
a$ = a$ + m$(df) + " is ": m%(df, 13) = m%(df, 13) + d2
Mstatus1:
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$ + "a little banged up.": GOTO Lp10
Ms3:
a$ = a$ + "in pain.": GOTO Lp10
Ms4:
a$ = a$ + "badly hurt.": GOTO Lp10
Ms5:
a$ = a$ + "gravely wounded.": GOTO Lp10
Ms6:
a$ = a$ + "mortally wounded.": 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 d%(10) = 2 THEN d%(10) = 3: GOTO Mdead2
'

IF df = 0 THEN die = 1: GOTO Lp10
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 THEN a%(a2, 4) = ro
NEXT
IF df = 36 THEN m%(37, 5) = ro
Mdead2:
GOSUB EnemyCheck: GOTO Lp10
END SUB

