' THE WONDERFUL WORLD OF EAMON DELUXE EDITION
'            BY FRANK Black
'
'   A COMPUTERIZED FANTASY ROLE-PLAYING SYSTEM
' BASED UPON THE APPLE II VERSION BY DONALD BROWN,
'    JOHN NELSON, TOM ZUCHOWSKI, & FRANK Black
'
' TEXT MOVER
' 21 FEB 1997 Update 27 MAY 1999
' ******
' Modified for "The Heart of Gold", 16 March 1997
'   This version also works with the text from the "GUIDE.DAT" file
' ******
' This program moves ALL of the text of an Eamon Deluxe adventure
'  back and forth between random access files and .TXT files.
'
' The purpose is to allow the use of spelling checkers which generally
'  mess up random access files.
'
'----------------------------------------------------------------------------
' Initialize variables for random access files
'
TYPE DESC
  text AS STRING * 255
END TYPE
DIM 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 rm AS ROOM

TYPE ARTIFACT
  ANAME AS STRING * 35: AD1 AS INTEGER: AD2 AS INTEGER: AD3 AS INTEGER
  AD4 AS INTEGER: AD5 AS INTEGER: AD6 AS INTEGER: AD7 AS INTEGER
  AD8 AS INTEGER
END TYPE
DIM 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 mon AS MONSTER

OPEN "NAME.DAT" FOR INPUT AS #1
INPUT #1, nr, naf, ne, nm, ANAME$, nd, ver
CLOSE

OPEN "HINTDIR.DAT" FOR INPUT AS #1
INPUT #1, nh: DIM 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

OPEN "GUIDEDIR.DAT" FOR INPUT AS #1
INPUT #1, ng: DIM g$(ng), g%(ng, 2)
FOR r = 1 TO ng
   LINE INPUT #1, g$(r)
   INPUT #1, g%(r, 1), g%(r, 2)
NEXT
CLOSE

'---------------------------------------------------------------------------
' Main Menu
'
Menu:
CLS
PRINT "<1> Transfer Eamon Deluxe random-access files to a sequential file."
PRINT "     This will write the names and descriptions of all rooms, artifacts,"
PRINT "     monsters, effects, and hints into one file called EMNTEXT.TXT.  It is a"
PRINT "     standard DOS text file which can be checked with a spelling-checker. (Never"
PRINT "     use a spelling-checker with random-access files!) "
PRINT
PRINT "<2> Transfer the sequential file back to random-access files."
PRINT "     This, obviously, is the opposite of option 1.  Use this to put the data"
PRINT "     back into your random-access files once you've checked the spelling (or"
PRINT "     whatever)."
PRINT
PRINT "Enter 1, 2, (or 3 to quit): "; : GOSUB GetKey
k = INT(VAL(k$)): IF k < 1 OR k > 3 THEN GOTO Menu
CLS
ON k GOTO RandomToSeq, SeqToRandom
END

'===========================================================================
' Transfer random files to a sequential file
'
RandomToSeq:
OPEN "ROOMS.DSC" FOR RANDOM AS #2 LEN = 255
OPEN "EMNTEXT.TXT" FOR OUTPUT AS #3
'
' Rooms
'
OPEN "ROOMS.DAT" FOR RANDOM AS #1 LEN = 101

IF nr > 0 THEN
  PRINT "Reading/Writing room #";
  FOR r = 1 TO nr
     LOCATE CSRLIN, 23: PRINT r; "/"; nr;
     GET #1, r, rm
     GET #2, r, ds
     PRINT #3, RTRIM$(rm.rname)
     PRINT #3, RTRIM$(ds.text)
  NEXT
  PRINT "....Done!"
END IF
CLOSE #1
'---------------------------------------------------------------------------
'   Artifacts
'
CLOSE #2: OPEN "artifact.dsc" FOR RANDOM AS #2 LEN = 255
OPEN "ARTIFACT.DAT" FOR RANDOM AS #1 LEN = 51

IF naf > 0 THEN
  PRINT "Reading/Writing artifact #";
  FOR a = 1 TO naf
     LOCATE CSRLIN, 27: PRINT a; "/"; naf;
     GET #1, a, art
     GET #2, a, ds
     PRINT #3, RTRIM$(art.ANAME)
     PRINT #3, RTRIM$(ds.text)
  NEXT
  PRINT "....Done!"
END IF
CLOSE #1
'---------------------------------------------------------------------------
'   Monsters
'
CLOSE #2: OPEN "monsters.dsc" FOR RANDOM AS #2 LEN = 255
OPEN "MONSTERS.DAT" FOR RANDOM AS #1 LEN = 61

IF nm > 0 THEN
  PRINT "Reading/Writing monster #";
  FOR m = 1 TO nm
     LOCATE CSRLIN, 26: PRINT m; "/"; nm;
     GET #1, m, mon
     GET #2, m, ds
     PRINT #3, RTRIM$(mon.mname)
     PRINT #3, RTRIM$(ds.text)
  NEXT
  PRINT "....Done!"
END IF
CLOSE #1: CLOSE #2
'---------------------------------------------------------------------------
'   Effects
'
OPEN "effect.dsc" FOR RANDOM AS #2 LEN = 255
IF ne > 0 THEN
  PRINT "Reading/Writing effect #";
  FOR r = 1 TO ne
     LOCATE CSRLIN, 25: PRINT r; "/"; ne;
     GET #2, r, ds
     PRINT #3, RTRIM$(ds.text)
  NEXT
  PRINT "....Done!"
END IF
CLOSE #2

'---------------------------------------------------------------------------
'  Hints
'
OPEN "HINTS.DSC" FOR RANDOM AS #1 LEN = 255
r2 = 0

IF nh > 0 THEN
  PRINT "Reading/Writing hints";
  FOR r = 1 TO nh
     PRINT #3, h$(r)
  NEXT
  FOR r = 1 TO h%(nh, 1) + h%(nh, 2) - 1
     GET #1, r, ds
     PRINT #3, RTRIM$(ds.text)
  NEXT
  PRINT "....Done!"
END IF
CLOSE #1
'---------------------------------------------------------------------------
'  Hitchhiker's Guide Simulator text
'
OPEN "GUIDE.DSC" FOR RANDOM AS #1 LEN = 255
r2 = 0

IF ng > 0 THEN
  PRINT "Reading/Writing Guide entries";
  FOR r = 1 TO ng
     PRINT #3, g$(r)
  NEXT
  FOR r = 1 TO g%(ng, 1) + g%(ng, 2) - 1
     GET #1, r, ds
     PRINT #3, RTRIM$(ds.text)
  NEXT
  PRINT "....Done!"
END IF
CLOSE
'
PRINT
PRINT "Data was saved in the file EMNTEXT.TXT in the "; ad$; " directory."
END
'===========================================================================
' Transfer the sequential file back to random files
SeqToRandom:
OPEN "rooms.dsc" FOR RANDOM AS #2 LEN = 255
OPEN "EMNTEXT.TXT" FOR INPUT AS #3
'
' Rooms
'
OPEN "ROOMS.DAT" FOR RANDOM AS #1 LEN = 101

IF nr > 0 THEN
  PRINT "Reading/Writing room #";
  FOR r = 1 TO nr
     LOCATE CSRLIN, 23: PRINT r; "/"; nr;
     GET #1, r, rm
     LINE INPUT #3, a$: rm.rname = a$
     PUT #1, r, rm
     LINE INPUT #3, a$
     ds.text = a$
     PUT #2, r, ds
  NEXT
  PRINT "....Done!"
END IF
CLOSE #1
'---------------------------------------------------------------------------
'   Artifacts
'
CLOSE #2: OPEN "artifact.dsc" FOR RANDOM AS #2 LEN = 255
OPEN "ARTIFACT.DAT" FOR RANDOM AS #1 LEN = 51

IF naf > 0 THEN
  PRINT "Reading/Writing artifact #";
  FOR a = 1 TO naf
     LOCATE CSRLIN, 27: PRINT a; "/"; naf;
     GET #1, a, art
     LINE INPUT #3, a$: art.ANAME = a$
     PUT #1, a, art
     LINE INPUT #3, a$: ds.text = a$
     PUT #2, a, ds
  NEXT
  PRINT "....Done!"
END IF
CLOSE #1
'---------------------------------------------------------------------------
'   Monsters
'
CLOSE #2: OPEN "monsters.dsc" FOR RANDOM AS #2 LEN = 255
OPEN "MONSTERS.DAT" FOR RANDOM AS #1 LEN = 61

IF nm > 0 THEN
  PRINT "Reading/Writing monster #";
  FOR m = 1 TO nm
     LOCATE CSRLIN, 26: PRINT m; "/"; nm;
     GET #1, m, mon
     LINE INPUT #3, a$: mon.mname = a$
     PUT #1, m, mon
     LINE INPUT #3, a$: ds.text = a$
     PUT #2, m, ds
  NEXT
  PRINT "....Done!"
END IF
CLOSE #1: CLOSE #2
'---------------------------------------------------------------------------
'   Effects
'
OPEN "effect.dsc" FOR RANDOM AS #2 LEN = 255
IF ne > 0 THEN
  PRINT "Reading/Writing effect #";
  FOR r = 1 TO ne
     LOCATE CSRLIN, 25: PRINT r; "/"; ne;
     LINE INPUT #3, a$: ds.text = a$
     PUT #2, r, ds
  NEXT
  PRINT "....Done!"
END IF
CLOSE #2

'---------------------------------------------------------------------------
'  Hints
'
OPEN "HINTS.DSC" FOR RANDOM AS #1 LEN = 255
r2 = 0

IF nh > 0 THEN
  PRINT "Reading/Writing hints";
  FOR r = 1 TO nh
     LINE INPUT #3, h$(r)
  NEXT
  FOR r = 1 TO h%(nh, 1) + h%(nh, 2) - 1
     LINE INPUT #3, a$: ds.text = a$
     PUT #1, r, ds
  NEXT
  PRINT "....Done!"
END IF
CLOSE #1
'---------------------------------------------------------------------------
'  Hitchhiker's Guide Simulator text
'
OPEN "GUIDE.DSC" FOR RANDOM AS #1 LEN = 255
r2 = 0

IF ng > 0 THEN
  PRINT "Reading/Writing Guide entries";
  FOR r = 1 TO ng
     LINE INPUT #3, g$(r)
  NEXT
  FOR r = 1 TO g%(ng, 1) + g%(ng, 2) - 1
     LINE INPUT #3, a$: ds.text = a$
     PUT #1, r, ds
  NEXT
  PRINT "....Done!"
END IF
CLOSE
'
KILL "EMNTEXT.TXT"
PRINT
PRINT "Data was restored.  EMNTEXT.TXT was deleted."
END
'---------------------------------------------------------------------------
' Get a single keypress
'
GetKey:
BS = POS(0): CC = 0
DO
   CC = CC + 1
   IF CC = CC1 THEN PRINT "/": LOCATE CSRLIN - 1, BS
   IF CC = CC2 THEN PRINT CHR$(179): LOCATE CSRLIN - 1, BS
   IF CC = CC3 THEN
      PRINT "\": LOCATE CSRLIN - 1, BS
      CC = 0
   END IF
   k$ = UCASE$(INKEY$)
LOOP UNTIL k$ <> ""
PRINT k$: RETURN

