'     Display/Erase visitors file for "The Jim Jacobson Adventures"
'        by Frank Black
'
'              Update:  21 MAY 2001
'

TYPE visitors
   pname AS STRING * 40: psex AS STRING * 3: v0 AS INTEGER: v1 AS INTEGER
   v2 AS INTEGER: v3 AS INTEGER: v4 AS INTEGER: v5 AS INTEGER: v6 AS INTEGER
   v7 AS INTEGER: v8 AS INTEGER: v9 AS INTEGER: v10 AS INTEGER: v11 AS INTEGER
   v12 AS INTEGER: v13 AS INTEGER: v14 AS INTEGER: v15 AS INTEGER
   v16 AS INTEGER: v17 AS INTEGER: v18 AS INTEGER: v19 AS INTEGER
   v20 AS INTEGER: v21 AS INTEGER: v22 AS INTEGER: v23 AS INTEGER
   v24 AS INTEGER: v25 AS INTEGER: v26 AS INTEGER
END TYPE
DIM v AS visitors
OPEN "VISITORS.DAT" FOR RANDOM AS #1 LEN = 97
GET #1, 1, v: nv = v.v26: nv$ = LTRIM$(RTRIM$(STR$(nv)))
CLS
IF nv = 0 THEN
  PRINT "There aren't any visitors on file": PRINT
  GOSUB GetKey: RUN "INTRO"
END IF
PRINT "Number of visitors: "; nv$
PRINT
PRINT " 1. List visitors"
PRINT " 2. Visitor history"
PRINT " 3. Erase visitors file"
PRINT " 4. Exit"
PRINT
PRINT "Hit 1-4 to make your choice:";
DO
  k = INT(VAL(INKEY$))
LOOP UNTIL k > 0 AND k < 5

IF k = 4 THEN RUN "INTRO"

IF k = 3 THEN
  CLS : PRINT "Erase all data?": PRINT : PRINT "Are you sure? (Y/N):";
  DO
    k$ = LCASE$(INKEY$)
  LOOP UNTIL k$ = "y" OR k$ = "n"
  IF k$ = "n" THEN RUN
  GOSUB Init: RUN "INTRO"
END IF

IF k = 1 THEN
  CLS : PRINT "Visitors on file --": PRINT : l = 2
  FOR m = 1 TO nv
     GET #1, m, v
     PRINT LTRIM$(RTRIM$(STR$(m))); ": "; v.pname: l = l + 1
     IF l > 21 THEN GOSUB GetKey
  NEXT
  IF l > 0 THEN PRINT : GOSUB GetKey
  RUN
END IF

CLS : PRINT "View history on which visitor (1-"; nv$; "):"
k$ = INKEY$
DO
  k = INT(VAL(INKEY$))
LOOP UNTIL k > 0 AND k <= nv
GET #1, k, v
'
'  Cave of the Mind
'
IF v.v21 > 0 THEN
  CLS : PRINT RTRIM$(v.pname); " has played the Cave of the Mind"; v.v21; "time";
  IF v.v21 > 1 THEN PRINT "s";
  PRINT ".": PRINT : PRINT : a$ = "The last time " + RTRIM$(v.psex) + " met"
  IF v.v0 + v.v1 = 0 THEN a$ = a$ + " no friends"
  IF v.v0 > 0 THEN a$ = a$ + " a fellow named A.J."
  IF v.v1 > 0 THEN
    IF v.v0 > 0 THEN a$ = a$ + " and"
    a$ = a$ + " a friendly chef."
  END IF
  IF v.v0 = 2 THEN m$ = "A.J.": GOSUB M1
  IF v.v1 = 2 THEN m$ = "the jolly chef": GOSUB M1
  IF v.v0 = 1 THEN m$ = "A.J.": GOSUB M2
  IF v.v1 = 1 THEN m$ = "the jolly chef": GOSUB M2
  GOSUB Lp0: PRINT : GOSUB GetKey
END IF
'
'  Zyphur
'
IF v.v22 > 0 THEN
  CLS : PRINT RTRIM$(v.pname); " has played the Zyphur Riverventure"; v.v22; "time";
  IF v.v22 > 1 THEN PRINT "s";
  PRINT ".": PRINT
  IF v.v7 > 0 THEN
    a$ = "There " + RTRIM$(v.psex)
    a$ = a$ + " met and disposed of the fearsom Black Warrior!"
    GOSUB Lp0
  END IF
  PRINT : a$ = "The last time " + RTRIM$(v.psex) + " met"
  IF v.v2 + v.v3 + v.v4 + v.v5 + v.v6 = 0 THEN a$ = a$ + " no friends"
  x = 0: IF v.v2 > 0 THEN a$ = a$ + " a fellow named A.J.": x = 1
  IF v.v3 > 0 THEN m$ = " a doctor named Benway": GOSUB M3
  IF v.v4 > 0 THEN m$ = " a poor soul known only as 'prisoner #13'": GOSUB M3
  IF v.v5 > 0 THEN m$ = " the famous Professor Axom": GOSUB M3
  IF v.v6 > 0 THEN m$ = " an enormous warrior in gold colored armor": GOSUB M3
  a$ = a$ + ".": GOSUB Lp0: PRINT : a$ = ""
  IF v.v2 = 2 THEN m$ = "A.J.": GOSUB M1
  IF v.v3 = 2 THEN m$ = "Doctor Benway": GOSUB M1
  IF v.v4 = 2 THEN m$ = "Prisoner #13": GOSUB M1
  IF v.v5 = 2 THEN m$ = "Professor Axom": GOSUB M1
  IF v.v6 = 2 THEN m$ = "the Gold Warrior": GOSUB M1
  IF v.v2 = 1 THEN m$ = "A.J.": GOSUB M2
  IF v.v3 = 1 THEN m$ = "Doctor Benway": GOSUB M2
  IF v.v4 = 1 THEN m$ = "Prisoner #13": GOSUB M2
  IF v.v5 = 1 THEN m$ = "Professor Axom": GOSUB M2
  IF v.v6 = 1 THEN m$ = "the Gold Warrior": GOSUB M2
  IF a$ <> "" THEN a$ = a$ + "."
  GOSUB Lp0: PRINT : a$ = ""
  PRINT : GOSUB GetKey
END IF
'
'  Devil's Tomb
'
IF v.v23 > 0 THEN
  CLS : PRINT RTRIM$(v.pname); " has played The Devil's Tomb"; v.v23; "time";
  IF v.v23 > 1 THEN PRINT "s";
  PRINT ".": PRINT
  IF v.v9 > 0 THEN
    a$ = "There " + RTRIM$(v.psex): IF v.v7 > 0 THEN a$ = a$ + " again"
    a$ = a$ + " met": IF v.v9 = 2 THEN a$ = a$ + " and disposed of"
    a$ = a$ + " the fearsom Black Warrior!"
    GOSUB Lp0: PRINT : a$ = ""
  END IF
  IF v.v8 > 0 THEN
    m$ = "The Gold Warrior"
    IF v.v8 = 2 THEN GOSUB M1
    IF v.v8 = 1 THEN GOSUB M2
  END IF
  PRINT : GOSUB GetKey
END IF
'
'  Abductor
'
IF v.v24 > 0 THEN
  CLS : PRINT RTRIM$(v.pname); " has played The Abductor's Quarters"; v.v24; "time";
  IF v.v24 > 1 THEN PRINT "s";
  PRINT ".": PRINT : PRINT : a$ = "The last time " + RTRIM$(v.psex) + " met"
  IF v.v10 + v.v11 + v.v12 = 0 THEN a$ = a$ + " no friends"
  IF v.v10 > 0 THEN a$ = a$ + " the jolly chef again"
  IF v.v11 > 0 THEN
    IF v.v10 > 0 THEN a$ = a$ + " and"
    a$ = a$ + " Professor Axom again"
  END IF
  IF v.v12 > 0 THEN
    IF v.v10 > 0 OR v.v11 > 0 THEN a$ = a$ + " and"
    a$ = a$ + " Prisoner #13 again."
  END IF
  IF v.v10 = 2 THEN m$ = "the jolly chef": GOSUB M1
  IF v.v11 = 2 THEN m$ = "Professor Axom": GOSUB M1
  IF v.v12 = 2 THEN m$ = "Prisoner #13": GOSUB M1
  IF v.v10 = 1 THEN m$ = "the jolly chef": GOSUB M2
  IF v.v11 = 1 THEN m$ = "Professor Axom": GOSUB M2
  IF v.v12 = 1 THEN m$ = "Prisoner #13": GOSUB M2
  GOSUB Lp0: PRINT : GOSUB GetKey
END IF

RUN

Init:
CLOSE
KILL "VISITORS.DAT"
OPEN "VISITORS.DAT" FOR RANDOM AS #1 LEN = 97
GET #1, 1, v
v.pname = "Nobody": v.psex = "he"
PUT #1, 1, v
CLOSE
RETURN

GetKey:
k$ = INKEY$: PRINT "Hit any key to continue..."
DO
LOOP UNTIL INKEY$ <> ""
CLS : l = 0: RETURN

'------------------------------
' Print a$ without wrap-around
'------------------------------
Lp0:
xm = 0: a$ = LTRIM$(a$)
IF LEN(a$) <= 79 THEN PRINT a$:  RETURN
FOR k = 79 TO 1 STEP -1
   IF MID$(a$, k, 1) = " " THEN
     PRINT LEFT$(a$, k - 1): a$ = RIGHT$(a$, LEN(a$) - k): k = 1: xm = 1
   END IF
NEXT: IF xm = 1 THEN GOTO Lp0

M1:
a$ = a$ + "  Unfortunatly, " + m$ + " died.": RETURN
M2:
a$ = a$ + "  Then " + RTRIM$(v.pname) + " savagely killed " + m$ + "!": RETURN
M3:
IF x > 0 THEN m$ = " and" + m$
x = x + 1: a$ = a$ + m$: RETURN

