 Rem File: EditcmdB for Dndbbs Version v5.0a Release r2.0
 Rem $Include: 'edit.inc'

 On Error Goto ErrMain0
 If Chained2=False Then
    Call Open.Arrays
    Call Get.Config
    Call Increase.Files
    Call Make.FileNames
    Call Open.Files
    Call Reset.Cursor
    Call Detect.Share
    Call Save.Screen2(0)
    Call Passwrd9(Var,"b")
    If Var=False Then
       Call Terminate.Program
       End
    Endif
 Endif
 Call Edit.Spell
MainExit0:
 End
ErrMain0:
 Resume MainExit0
 End

Sub Edit.Spell
 On Local Error Goto ErrResume45
 Call Edit.Status.Line
 If Lof(SpellFile)=SFalse Then
    Call Add.Spell
 Endif
 Do While Lost.Carrier=False
    If TempC=False Then
       Graphics.Off=False
       Strng="Spell Edit utility v"+Left$(Version$,4)+" menu:"
       Call IO.O
       Graphics.Off=True
       Strng=RT$(368,"[A]")+"dd"
       Call IO.O
       Strng=RT$(369,"[C]")+"hange"
       Call IO.O
       Strng=RT$(370,"[L]")+"ist"
       Call IO.O
       If Local.Mode Then
          Strng=RT$(591,"[P]")+"rint"
          Call IO.O
       Endif
       Strng=RT$(578,"[S]")+"earch"
       Call IO.O
       Graphics.Off=False
    Endif
    Strng="Spell edit option(q to quit)? "
    Line.Length=TempD
    No.Input.Out="Q"
    Call IO.I
    Select Case Ucase$(Out2)
    Case "A"
       If RT$(368,"[A]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Add.Spell
          Temp5!=Lof(SpellFile)/SpellRecLen
          Call Change.Spell
       Endif
    Case "C"
       If RT$(369,"[C]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Find.Spell(0)
          If Temp! Then
             Temp5!=Temp!
             Call Change.Spell
          Else
             Strng="Spell not found."
             Call IO.O
          Endif
       Endif
    Case "L"
       If RT$(370,"[L]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call List.Spell
       Endif
    Case "S"
       If RT$(578,"[S]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Search.Spells
       Endif
    Case "P"
       If Local.Mode Then
          If RT$(591,"[P]")="[*]" Then
             Strng="Command restricted.."
             Call IO.O
          Else
             Call Print.Spells
          Endif
       Endif
    Case "Q"
       Exit Do
    End Select
 Loop
 Close
 Call Clear.Status.Line
 If Chained2 Then
    Chain DND.Path+"EDIT.EXE"
 Endif
 Call Terminate.Program
ErrExit45:
 Exit Sub
ErrResume45:
 Resume ErrExit45
End Sub

Sub Add.Spell
 On Local Error Goto ErrResume46
 Temp5!=Lof(SpellFile)/SpellRecLen+1!
 SpellRecord.SpellName=Nul
 SpellRecord.Chant=Nul
 SpellRecord.Desc=Nul
 SpellRecord.Level=False
 SpellRecord.SpellType=False
 SpellRecord.Teleport=False
 SpellRecord.ClassType=False
 SpellRecord.Psionic=False
 SpellRecord.PsionicMode=False
 For Temp6=1 To MaxIngredients
    SpellRecord.Ingred(Temp6)=SFalse
 Next
 SpellRecord.SpellFlag=False
 SpellRecord.SpellEquate=Nul
 SpellRecord.Equation=False
 SpellRecord.Prefix1=""
 Call Write.Record(SpellFile,Temp5!)
 UserRecord.ObjectsCreated(8)=UserRecord.ObjectsCreated(8)+1#
 If User.Index Then
    Call Write.Record(UserFile,User.Index)
 Endif
ErrExit46:
 Exit Sub
ErrResume46:
 Resume ErrExit46
End Sub

Sub List.Spell
 On Local Error Goto ErrResume47
 Temp3!=Lof(SpellFile)/SpellRecLen
 Call Get.Record.Range(Temp!,Temp2!,Temp3!)
 Allow.Break=True
 Break=False
 Continuous=False
 For Temp5!=Temp! To Temp2!
    Call Read.Record(SpellFile,Temp5!)
    For VarQ=1 To 17
       Call Display.Spell(False,VarQ)
       If Break Then
          Exit For
       Endif
    Next
    If Break Then
       Exit For
    Endif
    If Continuous=False Then
       Call More.Prompt
       If No Or Quit Then
          Exit For
       Endif
    Endif
 Next
 Allow.Break=False
 Break=False
ErrExit47:
 Exit Sub
ErrResume47:
 Resume ErrExit47
End Sub

Sub Print.Spells
 On Local Error Goto ErrResume47a
 Strng="Printer port(1-3)? "
 Call IO.I
 VarP=Int(Val(Out2))
 If VarP>=1 And VarP<=3 Then
    Close #TempFile1
    VarP$="LPT"+Mid$(Str$(VarP),2)+":"
    Open VarP$ For Output As #TempFile1
    Temp3!=Lof(SpellFile)/SpellRecLen
    Call Get.Record.Range(Temp!,Temp2!,Temp3!)
    For Temp5!=Temp! To Temp2!
       Call Read.Record(SpellFile,Temp5!)
       For VarQ=1 To 16
          Call Print.Spell(VarQ)
       Next
       Print #TempFile1,Chr$(12);
    Next
 Endif
ErrExit47a:
 Close #TempFile1
 Exit Sub
ErrResume47a:
 Resume ErrExit47a
End Sub

Sub Change.Spell
 On Local Error Goto ErrResume48
 Call Read.Record(SpellFile,Temp5!)
 Do While Lost.Carrier=False
    Allow.Break=True
    Break=False
    For VarQ=1 To 17
       Call Display.Spell(True,VarQ)
       If Break Then
          Exit For
       Endif
    Next
    Allow.Break=False
    Break=False
    Graphics.Off=False
    Strng="Spell change option(q to quit)? "
    Line.Length=TempD
    No.Input.Out="Q"
    Call IO.I
    Select Case Ucase$(Out2)
    Case "A"
       If RT$(371,"[A]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Strng="Spell name(30 characters):"
          Call IO.O
          Strng="?"
          No.Input.Out=Nul
          Call IO.I
          Out2=Lcase$(Out2)
          SpellRecord.SpellName=Out2
       Endif
    Case "B"
       If RT$(372,"[B]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Strng="Spell chant(80 characters):"
          Call IO.O
          Strng="?"
          No.Input.Out=Nul
          Call IO.I
          Out2=Ucase$(Out2)
          SpellRecord.Chant=Out2
       Endif
    Case "C"
       If RT$(373,"[C]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Strng="Spell cast description(80 characters):"
          Call IO.O
          Strng="?"
          No.Input.Out=Nul
          Call IO.I
          SpellRecord.Desc=Out2
       Endif
    Case "D"
       If RT$(374,"[D]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Strng="Spell level(1-32767)? "
          No.Input.Out="1"
          Call IO.I
          SpellRecord.Level=Int(Val(Out2))
       Endif
    Case "E"
       If RT$(375,"[E]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Spell.Types1
          Strng="Spell type option(q to quit)? "
          Line.Length=TempD
          No.Input.Out="Q"
          Call IO.I
          Out2=Ucase$(Out2)
          Temp5=Instr("ABCDEFGHIJKLMNOPRSTUVWXYZ12345678Q",Out2)
          Select Case Temp5
          Case 0
             SpellRecord.SpellType=0
          Case Curse
             If RT$(684,"[?]")="[*]" Then
                Strng="Command restricted.."
                Call IO.O
             Else
                SpellRecord.SpellType=Curse
             Endif
          Case Damnate
             If RT$(685,"[?]")="[*]" Then
                Strng="Command restricted.."
                Call IO.O
             Else
                SpellRecord.SpellType=Damnate
             Endif
          Case Resurrect
             If RT$(695,"[?]")="[*]" Then
                Strng="Command restricted.."
                Call IO.O
             Else
                SpellRecord.SpellType=Resurrect
             Endif
          Case GrantWish
             If RT$(696,"[?]")="[*]" Then
                Strng="Command restricted.."
                Call IO.O
             Else
                SpellRecord.SpellType=GrantWish
             Endif
          Case StealWish
             If RT$(699,"[?]")="[*]" Then
                Strng="Command restricted.."
                Call IO.O
             Else
                SpellRecord.SpellType=StealWish
             Endif
          Case 1 To 28
             If RT$(381+Temp5,"[?]")="[*]" Then
                Strng="Command restricted.."
                Call IO.O
             Else
                SpellRecord.SpellType=Temp5
                If Temp5=10 Then
                   SpellRecord.Teleport=False
                   Do While Lost.Carrier=False
                      Graphics.Off=True
                      If TempC=False Then
                         Strng=RT$(410,"[R]")+"oom prompt for teleport"
                         Call IO.O
                         Strng=RT$(411,"[T]")+"eleport to room number"
                         Call IO.O
                         Graphics.Off=False
                      Endif
                      Strng="Spell teleport option(q to quit)? "
                      Line.Length=TempD
                      No.Input.Out="Q"
                      Call IO.I
                      Select Case Ucase$(Out2)
                      Case "R"
                         If RT$(410,"[R]")="[*]" Then
                            Strng="Command restricted.."
                            Call IO.O
                         Else
                            SpellRecord.Teleport=True
                         Endif
                      Case "T"
                         If RT$(411,"[T]")="[*]" Then
                            Strng="Command restricted.."
                            Call IO.O
                         Else
                            Strng="Room number it teleports to"
                            Var!=Lof(RoomFile)/RoomRecLen
                            Call Get.Record.Range2(SFalse,Var!,Var2!)
                            SpellRecord.Teleport=Var2!
                         Endif
                      Case "Q"
                         Exit Do
                      End Select
                   Loop
                Endif
             Endif
          End Select
       Endif
    Case "F"
       If RT$(376,"[F]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Strng="Spell is psionic(y/n)? "
          Line.Length=TempD
          No.Input.Out="Y"
          Call IO.I
          SpellRecord.Psionic=False
          SpellRecord.PsionicMode=False
          If Yes Then
             SpellRecord.Psionic=True
             SpellRecord.PsionicMode=False
             SpellRecord.SpellType=15
             Do While Lost.Carrier=False
                Graphics.Off=True
                If TempC=False Then
                   Strng=RT$(412,"[A]")+"ttack mode"
                   Call IO.O
                   Strng=RT$(413,"[D]")+"efense mode"
                   Call IO.O
                   Graphics.Off=False
                Endif
                Strng="Spell psionic option(q to quit)? "
                Line.Length=TempD
                No.Input.Out="Q"
                Call IO.I
                Select Case Ucase$(Out2)
                Case "A"
                   If RT$(412,"[A]")="[*]" Then
                      Strng="Command restricted.."
                      Call IO.O
                   Else
                      SpellRecord.PsionicMode=1
                   Endif
                Case "D"
                   If RT$(413,"[D]")="[*]" Then
                      Strng="Command restricted.."
                      Call IO.O
                   Else
                      SpellRecord.PsionicMode=2
                   Endif
                Case "Q"
                   Exit Do
                End Select
             Loop
          Endif
       Endif
    Case "G"
       If RT$(377,"[G]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Do While Lost.Carrier=False
             Graphics.Off=True
             If TempC=False Then
                For Temp5=1 To MaxClasses
                   Strng=RT$(413+Temp5,"["+Chr$(64+Temp5)+"]")
                   Strng=Strng+Rtrim$(Class.Name(Temp5))
                   Call IO.O
                Next
                Strng=RT$(422,"[N]")+"one"
                Call IO.O
                Strng=RT$(423,"[X]")+"All"
                Call IO.O
                Graphics.Off=False
             Endif
             Strng="Spell class option(q to quit)? "
             Line.Length=TempD
             No.Input.Out="Q"
             Call IO.I
             Out2=Ucase$(Out2)
             Select Case Out2
             Case "A" To "H"
                Temp5=Instr("ABCDEFGH",Out2)
                If RT$(413+Temp5,"[?]")="[*]" Then
                   Strng="Command restricted.."
                   Call IO.O
                Else
                   SpellRecord.ClassType=SpellRecord.ClassType Or 2^Temp5
                Endif
             Case "N"
                If RT$(422,"[N]")="[*]" Then
                   Strng="Command restricted.."
                   Call IO.O
                Else
                   SpellRecord.ClassType=False
                Endif
             Case "X"
                If RT$(423,"[X]")="[*]" Then
                   Strng="Command restricted.."
                   Call IO.O
                Else
                   For Temp5=1 To MaxClasses
                      SpellRecord.ClassType=SpellRecord.ClassType Or 2^Temp5
                   Next
                Endif
             Case "Q"
                Exit Do
             End Select
          Loop
       Endif
    Case "H"
       If RT$(378,"[H]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Strng="Enter five treasure items for spell ingredients:"
          Call IO.O
          Strng="Press "+Enter$+" for none."
          Call IO.O
          Graphics.Off=True
          For Temp9=1 To MaxIngredients
             Call Find.Treasure
             SpellRecord.Ingred(Temp9)=TempC!
          Next
          Graphics.Off=False
       Endif
    Case "I"
       If RT$(379,"[I]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Do While Lost.Carrier=False
             Graphics.Off=True
             If TempC=False Then
                Strng=RT$(424,"[A]")+"use command"
                Call IO.O
                Strng=RT$(425,"[B]")+"read scroll"
                Call IO.O
                Strng=RT$(426,"[C]")+"cast spell"
                Call IO.O
                Strng=RT$(427,"[N]")+"one"
                Call IO.O
                Strng=RT$(428,"[X]")+"All"
                Call IO.O
                Graphics.Off=False
             Endif
             Strng="Spell casting type ingredient option(q to quit)? "
             Line.Length=TempD
             No.Input.Out="Q"
             Call IO.I
             Select Case Ucase$(Out2)
             Case "A"
                If RT$(424,"[A]")="[*]" Then
                   Strng="Command restricted.."
                   Call IO.O
                Else
                   SpellRecord.SpellFlag=SpellRecord.SpellFlag Or Use.Spell.Type
                Endif
             Case "B"
                If RT$(425,"[B]")="[*]" Then
                   Strng="Command restricted.."
                   Call IO.O
                Else
                   SpellRecord.SpellFlag=SpellRecord.SpellFlag Or Scroll.Spell.Type
                Endif
             Case "C"
                If RT$(426,"[C]")="[*]" Then
                   Strng="Command restricted.."
                   Call IO.O
                Else
                   SpellRecord.SpellFlag=SpellRecord.SpellFlag Or Cast.Spell.Type
                Endif
             Case "N"
                If RT$(427,"[N]")="[*]" Then
                   Strng="Command restricted.."
                   Call IO.O
                Else
                   SpellRecord.SpellFlag=False
                Endif
             Case "X"
                If RT$(428,"[X]")="[*]" Then
                   Strng="Command restricted.."
                   Call IO.O
                Else
                   SpellRecord.SpellFlag=SpellRecord.SpellFlag Or Use.Spell.Type
                   SpellRecord.SpellFlag=SpellRecord.SpellFlag Or Scroll.Spell.Type
                   SpellRecord.SpellFlag=SpellRecord.SpellFlag Or Cast.Spell.Type
                Endif
             Case "Q"
                Exit Do
             End Select
          Loop
       Endif
    Case "J"
       If RT$(380,"[J]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Line.Length=TempD
          No.Input.Out="Y"
          Strng="Spell has offense equation(y/n)? "
          Call IO.I
          SpellRecord.Equation=False
          SpellRecord.SpellEquate=Nul
          If Yes Then
             Strng="Enter spell equation:"
             Call IO.I
             If Len(Out2) Then
                SpellRecord.Equation=True
                SpellRecord.SpellEquate=Ucase$(Out2)
             Endif
          Endif
       Endif
    Case "K"
       If RT$(381,"[K]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Graphics.Off=True
          If ANSIPrefixChar=Nul Then
             Strng="ANSI prefix codes not enabled."
             Call IO.O
             Call More.Prompt
          Else
             Do
                Strng="ANSI prefix code(8 characters, ? for help):"
                Call IO.O
                Strng="?"
                No.Input.Out=Nul
                Call IO.I
                Out2=Ucase$(Out2)
                If Out2="?" Then
                   Call Display.ANSI.Prefixes
                Else
                   Call Check.ANSI.Prefix(V%)
                   If V% Then
                      SpellRecord.Prefix1=Out2
                      Exit Do
                   Endif
                   Strng="Invalid ANSI code."
                   Call IO.O
                   Call More.Prompt
                Endif
             Loop
          Endif
       Endif
    Case "Q"
       Exit Do
    End Select
 Loop
 Call Write.Record(SpellFile,Temp5!)
 Strng="Spell '"+Rtrim$(SpellRecord.SpellName)+"' changed."
 Call IO.O
ErrExit48:
 Exit Sub
ErrResume48:
 Resume ErrExit48
End Sub

Sub Spell.Types1
 On Local Error Goto ErrResume49
 If TempC Then
    Exit Sub
 Endif
 Graphics.Off=True
 Strng=RT$(382,"[A]")+"Enchant      "+RT$(399,"[S]")+"Detect Trap"
 Call IO.O
 Strng=RT$(383,"[B]")+"Offense      "+RT$(400,"[T]")+"Intoxicate"
 Call IO.O                           
 Strng=RT$(384,"[C]")+"Bless        "+RT$(401,"[U]")+"Set Trap"
 Call IO.O
 Strng=RT$(385,"[D]")+"Wish         "+RT$(402,"[V]")+"Hide"
 Call IO.O
 Strng=RT$(386,"[E]")+"Poison       "+RT$(403,"[W]")+"Search"
 Call IO.O
 Strng=RT$(387,"[F]")+"Vigor        "+RT$(404,"[X]")+"Invisibility"
 Call IO.O
 Strng=RT$(388,"[G]")+"Heal         "+RT$(405,"[Y]")+"Identify"
 Call IO.O
 Strng=RT$(389,"[H]")+"Curepoison   "+RT$(406,"[Z]")+"Enlighten"
 Call IO.O
 Strng=RT$(390,"[I]")+"Level Drain  "+RT$(407,"[1]")+"Illuminate"
 Call IO.O
 Strng=RT$(391,"[J]")+"Teleport     "+RT$(408,"[2]")+"Psyche"
 Call IO.O
 Strng=RT$(392,"[K]")+"Befuddle     "+RT$(409,"[3]")+"Telepathy"
 Call IO.O
 Strng=RT$(393,"[L]")+"Turn Undead  "+RT$(684,"[4]")+"Curse"
 Call IO.O
 Strng=RT$(394,"[M]")+"Pass Door    "+RT$(685,"[5]")+"Damnate"
 Call IO.O
 Strng=RT$(395,"[N]")+"Conjure      "+RT$(695,"[6]")+"Resurrect"
 Call IO.O
 Strng=RT$(396,"[O]")+"Psionic      "+RT$(696,"[7]")+"Grant Wish"
 Call IO.O
 Strng=RT$(397,"[P]")+"Detect Lock  "+RT$(699,"[8]")+"Steal Wish"
 Call IO.O
 Strng=RT$(398,"[R]")+"Detect Evil"
 Call IO.O
 Graphics.Off=False
ErrExit49:
 Exit Sub
ErrResume49:
 Resume ErrExit49
End Sub

Sub Spell.Types2
 On Local Error Goto ErrResume50
 If TempC Then
    Exit Sub
 Endif
 Graphics.Off=True
 Strng="[A]Enchant      [S]Detect Trap"
 Call IO.O
 Strng="[B]Offense      [T]Intoxicate"
 Call IO.O
 Strng="[C]Bless        [U]Set Trap"
 Call IO.O
 Strng="[D]Wish         [V]Hide"
 Call IO.O
 Strng="[E]Poison       [W]Search"
 Call IO.O
 Strng="[F]Vigor        [X]Invisibility"
 Call IO.O
 Strng="[G]Heal         [Y]Identify"
 Call IO.O
 Strng="[H]Curepoison   [Z]Enlighten"
 Call IO.O
 Strng="[I]Level Drain  [1]Illuminate"
 Call IO.O
 Strng="[J]Teleport     [2]Psyche"
 Call IO.O
 Strng="[K]Befuddle     [3]Telepathy"
 Call IO.O
 Strng="[L]Turn Undead  [4]Curse"
 Call IO.O
 Strng="[M]Pass Door    [5]Damnate"
 Call IO.O
 Strng="[N]Conjure      [6]Resurrect"
 Call IO.O
 Strng="[O]Psionic      [7]Grant Wish"
 Call IO.O
 Strng="[P]Detect Lock  [8]Steal Wish"
 Call IO.O
 Strng="[R]Detect Evil"
 Call IO.O
 Graphics.Off=False
ErrExit50:
 Exit Sub
ErrResume50:
 Resume ErrExit50
End Sub

Sub Search.Spells
 On Local Error Goto ErrResume58
 Do While Lost.Carrier=False
    Temp1$=Nul
    Temp2$=Nul
    Temp3=False
    Temp4=False
    Temp6=False
    Temp7=False
    Temp8=False
    Temp9=False
    Do While Lost.Carrier=False
       Graphics.Off=True
       If TempC=False Then
          Strng="[A]spell name substring"
          If Temp1$<>Nul Then
             Strng=Strng+Space$(30-Len(Strng))
             Strng=Strng+"("+Temp1$+")"
          Endif
          Call IO.O
          Strng="[B]chant substring"
          If Temp2$<>Nul Then
             Strng=Strng+Space$(30-Len(Strng))
             Strng=Strng+"("+Temp2$+")"
          Endif
          Call IO.O
          Strng="[C]spell level"
          If Temp3 Then
             Strng=Strng+Space$(30-Len(Strng))
             Strng=Strng+"(selected)"
          Endif
          Call IO.O
          Strng="[D]psionic spells"
          If Temp4 Then
             Strng=Strng+Space$(30-Len(Strng))
             Strng=Strng+"(selected)"
          Endif
          Call IO.O
          Strng="[E]spell type"
          If Temp6 Then
             Strng=Strng+Space$(30-Len(Strng))
             Strng=Strng+"(Type:"+Str$(Temp6)+")"
          Endif
          Call IO.O
          Strng="[F]requires ingredients"
          If Temp7 Then
             Strng=Strng+Space$(30-Len(Strng))
             Strng=Strng+"(selected)"
          Endif
          Call IO.O
          Strng="[G]casting type"
          If Temp8 Then
             Strng=Strng+Space$(30-Len(Strng))
             Select Case Temp8
             Case 1
                Strng=Strng+"(use)"
             Case 2
                Strng=Strng+"(read)"
             Case 3
                Strng=Strng+"(cast)"
             End Select
          Endif
          Call IO.O
          Strng="[H]equation"
          If Temp9 Then
             Strng=Strng+Space$(30-Len(Strng))
             Strng=Strng+"(selected)"
          Endif
          Call IO.O
          Graphics.Off=False
       Endif
       Strng="Spell search option(S to search, Q to quit)? "
       Line.Length=TempD
       No.Input.Out="Q"
       Call IO.I
       Select Case Ucase$(Out2)
       Case "A"
          Strng="Spell name substring? "
          Call IO.I
          Out2=Lcase$(Out2)
          Temp1$=Out2
       Case "B"
          Strng="Chant substring? "
          Call IO.I
          Out2=Ucase$(Out2)
          Temp2$=Out2
       Case "C"
          Strng="Spell level? "
          Call IO.I
          Temp3=Int(Val(Out2))
       Case "D"
          Temp4=True
       Case "E"
          Call Spell.Types2
          Strng="Spell type? "
          Line.Length=TempD
          No.Input.Out="A"
          Call IO.I
          Out2=Ucase$(Out2)
          Temp6=Instr("ABCDEFGHIJKLMNOPRSTUVWXYZ12345678",Out2)
       Case "F"
          Temp7=True
       Case "G"
          Graphics.Off=True
          If TempC=False Then
             Strng="[1]use command"
             Call IO.O
             Strng="[2]read scroll"
             Call IO.O
             Strng="[3]cast spell"
             Call IO.O
          Endif
          Graphics.Off=False
          Line.Length=TempD
          Strng="Casting type(1,2,3,<enter>=none)? "
          Call IO.I
          Select Case Out2
          Case "1"
             Temp8=Use.Spell.Type
          Case "2"
             Temp8=Scroll.Spell.Type
          Case "3"
             Temp8=Cast.Spell.Type
          Case Else
             Temp8=False
          End Select
       Case "H"
          Temp9=True
       Case "S"
          Temp5!=Lof(SpellFile)/SpellRecLen
          Call Get.Record.Range(Temp!,Temp2!,Temp5!)
          Allow.Break=False
          Break=False
          Continuous=False
          VarZ1!=0!
          VarZ2!=0!
          If Temp1$<>Nul Then
             VarZ=Instr(Temp1$,"#")
             If VarZ Then
                VarZ2!=Int(Val(Mid$(Temp1$,VarZ+1)))
                Temp1$=Left$(Temp1$,VarZ-1)
             Endif
          Endif
          VarZ3!=0!
          VarZ4!=0!
          If Temp2$<>Nul Then
             VarZ=Instr(Temp2$,"#")
             If VarZ Then
                VarZ4!=Int(Val(Mid$(Temp2$,VarZ+1)))
                Temp2$=Left$(Temp2$,VarZ-1)
             Endif
          Endif
          For Temp5!=Temp! To Temp2!
             TempX=False
             Call Read.Record(SpellFile,Temp5!)
             If Temp1$<>Nul Then
                Out3=Rtrim$(SpellRecord.SpellName)
                Call InstrSUB(VarX,Out3,Temp1$)
                If VarX Then
                   VarZ1!=VarZ1!+1!
                   If VarZ2!=0! Or VarZ1!=VarZ2! Then
                      TempX=True
                   Endif
                Endif
             Endif
             If Temp2$<>Nul Then
                Out3=Rtrim$(SpellRecord.Chant)
                Call InstrSUB(VarX,Out3,Temp2$)
                If VarX Then
                   VarZ3!=VarZ3!+1!
                   If VarZ4!=0! Or VarZ3!=VarZ4! Then
                      TempX=True
                   Endif
                Endif
             Endif
             If Temp3 Then
                If SpellRecord.Level=Temp3 Then
                   TempX=True
                Endif
             Endif
             If Temp4 Then
                If SpellRecord.Psionic Then
                   TempX=True
                Endif
             Endif
             If Temp6 Then
                If SpellRecord.SpellType=Temp6 Then
                   TempX=True
                Endif
             Endif
             If Temp7 Then
                For TempY=1 To MaxIngredients
                   If SpellRecord.Ingred(TempY)>False Then
                      TempX=True
                      Exit For
                   Endif
                Next
             Endif
             If Temp8 Then
                If SpellRecord.SpellFlag And Temp8 Then
                   TempX=True
                Endif
             Endif
             If Temp9 Then
                If SpellRecord.Equation=True Then
                   TempX=True
                Endif
             Endif
             If TempX Then
                For VarQ=1 To 17
                   Call Display.Spell(False,VarQ)
                   If Break Then
                      Exit For
                   Endif
                Next
                If Break Then
                   Exit For
                Endif
                If Continuous=False Then
                   Call More.Prompt
                   If No Or Quit Then
                      Exit For
                   Endif
                Endif
             Endif
          Next
          Allow.Break=False
          Break=False
          Exit Do
       Case "Q"
          Exit Sub
       End Select
    Loop
 Loop
ErrExit58:
 Exit Sub
ErrResume58:
 Resume ErrExit58
End Sub

Sub Display.Spell(TempX,Var)
 On Local Error Goto ErrResume109
 If TempX Then
    If TempC Then
       Exit Sub
    Endif
 Endif
 Select Case Var
 Case 1
 Graphics.Off=False
 Strng="Spell number"+Str$(Temp5!)+":"
 Call IO.O
 Graphics.Off=True
 Case 2
 If TempX Then
    Strng=RT$(371,"[A]")
 Endif
 Strng=Strng+"Spell name: "+Rtrim$(SpellRecord.SpellName)
 Call IO.O
 Case 3
 If TempX Then
    Strng=RT$(372,"[B]")
 Endif
 Strng=Strng+"Spell chant: "+Rtrim$(SpellRecord.Chant)
 Call IO.O
 Case 4
 If TempX Then
    Strng=RT$(373,"[C]")
 Endif
 Strng=Strng+"Spell cast description: "
 Call IO.O
 Case 5
 Strng=Rtrim$(SpellRecord.Desc)
 If Strng=Nul Then
    Strng="<none>"
 Endif
 Call IO.O
 Case 6
 If TempX Then
    Strng=RT$(374,"[D]")
 Endif
 Strng=Strng+"Spell level:"+Str$(SpellRecord.Level)
 Call IO.O
 Case 7
 If TempX Then
    Strng=RT$(375,"[E]")
 Endif
 Strng=Strng+"Spell type: "
 Select Case SpellRecord.SpellType
 Case 1
    Out2="Enchant"
 Case 2
    Out2="Offense"
 Case 3
    Out2="Bless"
 Case 4
    Out2="Wish"
 Case 5
    Out2="Poison"
 Case 6
    Out2="Vigor"
 Case 7
    Out2="Heal"
 Case 8
    Out2="Curepoison"
 Case 9
    Out2="Level Drain"
 Case 10
    If SpellRecord.Teleport<SFalse Then
       Out2="Prompts for teleport room"
    Else
       Out2="Teleport to Room"+Str$(SpellRecord.Teleport)
    Endif
 Case 11
    Out2="Befuddle"
 Case 12
    Out2="Turn Undead"
 Case 13
    Out2="Pass Door"
 Case 14
    Out2="Conjure"
 Case 15
    Out2="Psionic"
 Case 16
    Out2="Detect Lock"
 Case 17
    Out2="Detect Evil"
 Case 18
    Out2="Detect Trap"
 Case 19
    Out2="Intoxicate"
 Case 20
    Out2="Set Trap"
 Case 21
    Out2="Hide"
 Case 22
    Out2="Search"
 Case 23
    Out2="Invisibility"
 Case 24
    Out2="Identify"
 Case 25
    Out2="Enlighten"
 Case 26
    Out2="Illuminate"
 Case 27
    Out2="Psyche"
 Case 28
    Out2="Telepathy"
 Case 29
    Out2="Curse"
 Case 30
    Out2="Damnate"
 Case 31
    Out2="Resurrect"
 Case 32
    Out2="Grant Wish"
 Case 33
    Out2="Steal Wish"
 Case Else
    Out2="<none>"
 End Select
 Strng=Strng+Out2
 Call IO.O
 Case 8
 If TempX Then
    Strng=RT$(376,"[F]")
 Endif
 Strng=Strng+"Spell is psionic spell: "
 If SpellRecord.Psionic=False Then
    Strng=Strng+"No"
 Else
    Strng=Strng+"Yes, "
    Select Case SpellRecord.PsionicMode
    Case 1
       Strng=Strng+"Attack"
    Case 2
       Strng=Strng+"Defense"
    Case Else
       Strng=Strng+"<none>"
    End Select
 Endif
 Call IO.O
 Case 9
 If TempX Then
    Strng=RT$(377,"[G]")
 Endif
 Strng=Strng+"Character classes which can cast this spell:"
 Call IO.O
 Case 10
 TempA=False
 For TempB=1 To MaxClasses
    If SpellRecord.ClassType And 2^TempB Then
       Strng2=Class.Name(TempB)
       Strng2=Rtrim$(Strng2)
       Mid$(Strng2,1,1)=Ucase$(Mid$(Strng2,1,1))
       Strng=Strng+Strng2+", "
       TempA=True
    Endif
 Next
 If TempA Then
    Strng=Left$(Strng,Len(Strng)-2)+"."
 Else
    Strng="<none>"
 Endif
 Call IO.O
 Case 11
 If TempX Then
    Strng=RT$(378,"[H]")
 Endif
 Strng=Strng+"Spell ingredients:"
 Call IO.O
 Case 12
 TempA=False
 For TempB=1 To MaxIngredients
    TempB!=SpellRecord.Ingred(TempB)
    If TempB!>SFalse And TempB!<=Lof(TreasureFile)/TreasureRecLen Then
       Call Read.Record(TreasureFile,TempB!)
       Strng2=TreasureRecord.TreasureName
       Strng2=Rtrim$(Strng2)
       Strng2=Lcase$(Strng2)
       Mid$(Strng2,1,1)=Ucase$(Mid$(Strng2,1,1))
       Strng=Strng+Strng2+", "
       TempA=True
    Endif
 Next
 If TempA Then
    Strng=Left$(Strng,Len(Strng)-2)+"."
 Else
    Strng="<none>"
 Endif
 Call IO.O
 Case 13
 If TempX Then
    Strng=RT$(379,"[I]")
 Endif
 Strng=Strng+"Spell casting type which requires ingredients:"
 Call IO.O
 Case 14
 TempA=False
 If SpellRecord.SpellFlag And Use.Spell.Type Then
    Strng="use command, "
    TempA=True
 Endif
 If SpellRecord.SpellFlag And Scroll.Spell.Type Then
    Strng=Strng+"read scroll, "
    TempA=True
 Endif
 If SpellRecord.SpellFlag And Cast.Spell.Type Then
    Strng=Strng+"cast spell, "
    TempA=True
 Endif
 If TempA Then
    Strng=Left$(Strng,Len(Strng)-2)+"."
 Else
    Strng="<none>"
 Endif
 Call IO.O
 Case 15
 If TempX Then
    Strng=RT$(380,"[J]")
 Endif
 Strng=Strng+"Spell has offense equation: "
 If SpellRecord.Equation Then
    Strng=Strng+"Yes"
    Call IO.O
 Else
    Strng=Strng+"No"
    Call IO.O
 Endif
 Case 16
 If SpellRecord.Equation Then
    Strng=SpellRecord.SpellEquate
    Strng=Rtrim$(Strng)
    Strng="Equation: "+Strng
    Call IO.O
 Endif
 Case 17
 If TempX Then
    Strng=RT$(381,"[K]")
 Endif
 Strng=Strng+"ANSI Prefix code: "
 If Rtrim$(SpellRecord.Prefix1)=Nul Then
    Strng=Strng+"<none>"
 Else
    Strng=Strng+Rtrim$(SpellRecord.Prefix1)
 Endif
 Call IO.O
 End Select
ErrExit109:
 Exit Sub
ErrResume109:
 Resume ErrExit109
End Sub

Sub Print.Spell(Var)
 On Local Error Goto ErrResume109a
 Select Case Var
 Case 1
 Graphics.Off=False
 Strng="Spell number"+Str$(Temp5!)+":"
 Print #TempFile1,Strng
 Graphics.Off=True
 Case 2
 Strng=Nul
 Strng=Strng+"Spell name: "+Rtrim$(SpellRecord.SpellName)
 Print #TempFile1,Strng
 Case 3
 Strng=Nul
 Strng=Strng+"Spell chant: "+Rtrim$(SpellRecord.Chant)
 Print #TempFile1,Strng
 Case 4
 Strng=Nul
 Strng=Strng+"Spell cast description: "
 Print #TempFile1,Strng
 Case 5
 Strng=Rtrim$(SpellRecord.Desc)
 If Strng=Nul Then
    Strng="<none>"
 Endif
 Print #TempFile1,Strng
 Case 6
 Strng=Nul
 Strng=Strng+"Spell level:"+Str$(SpellRecord.Level)
 Print #TempFile1,Strng
 Case 7
 Strng=Nul
 Strng=Strng+"Spell type: "
 Select Case SpellRecord.SpellType
 Case 1
    Out2="Enchant"
 Case 2
    Out2="Offense"
 Case 3
    Out2="Bless"
 Case 4
    Out2="Wish"
 Case 5
    Out2="Poison"
 Case 6
    Out2="Vigor"
 Case 7
    Out2="Heal"
 Case 8
    Out2="Curepoison"
 Case 9
    Out2="Level Drain"
 Case 10
    If SpellRecord.Teleport<SFalse Then
       Out2="Prompts for teleport room"
    Else
       Out2="Teleport to Room"+Str$(SpellRecord.Teleport)
    Endif
 Case 11
    Out2="Befuddle"
 Case 12
    Out2="Turn Undead"
 Case 13
    Out2="Pass Door"
 Case 14
    Out2="Conjure"
 Case 15
    Out2="Psionic"
 Case 16
    Out2="Detect Lock"
 Case 17
    Out2="Detect Evil"
 Case 18
    Out2="Detect Trap"
 Case 19
    Out2="Intoxicate"
 Case 20
    Out2="Set Trap"
 Case 21
    Out2="Hide"
 Case 22
    Out2="Search"
 Case 23
    Out2="Invisibility"
 Case 24
    Out2="Identify"
 Case 25
    Out2="Enlighten"
 Case 26
    Out2="Illuminate"
 Case 27
    Out2="Psyche"
 Case 28
    Out2="Telepathy"
 Case 29
    Out2="Curse"
 Case 30
    Out2="Damnate"
 Case 31
    Out2="Resurrect"
 Case 32
    Out2="Grant Wish"
 Case 33
    Out2="Steal Wish"
 Case Else
    Out2="<none>"
 End Select
 Strng=Strng+Out2
 Print #TempFile1,Strng
 Case 8
 Strng=Nul
 Strng=Strng+"Spell is psionic spell: "
 If SpellRecord.Psionic=False Then
    Strng=Strng+"No"
 Else
    Strng=Strng+"Yes, "
    Select Case SpellRecord.PsionicMode
    Case 1
       Strng=Strng+"Attack"
    Case 2
       Strng=Strng+"Defense"
    Case Else
       Strng=Strng+"<none>"
    End Select
 Endif
 Print #TempFile1,Strng
 Case 9
 Strng=Nul
 Strng=Strng+"Character classes which can cast this spell:"
 Print #TempFile1,Strng
 Case 10
 Strng=Nul
 TempA=False
 For TempB=1 To MaxClasses
    If SpellRecord.ClassType And 2^TempB Then
       Strng2=Class.Name(TempB)
       Strng2=Rtrim$(Strng2)
       Mid$(Strng2,1,1)=Ucase$(Mid$(Strng2,1,1))
       Strng=Strng+Strng2+", "
       TempA=True
    Endif
 Next
 If TempA Then
    Strng=Left$(Strng,Len(Strng)-2)+"."
 Else
    Strng="<none>"
 Endif
 Print #TempFile1,Strng
 Case 11
 Strng=Nul
 Strng=Strng+"Spell ingredients:"
 Print #TempFile1,Strng
 Case 12
 TempA=False
 For TempB=1 To MaxIngredients
    TempB!=SpellRecord.Ingred(TempB)
    If TempB!>SFalse And TempB!<=Lof(TreasureFile)/TreasureRecLen Then
       Call Read.Record(TreasureFile,TempB!)
       Strng2=TreasureRecord.TreasureName
       Strng2=Rtrim$(Strng2)
       Strng2=Lcase$(Strng2)
       Mid$(Strng2,1,1)=Ucase$(Mid$(Strng2,1,1))
       Strng=Strng+Strng2+", "
       TempA=True
    Endif
 Next
 If TempA Then
    Strng=Left$(Strng,Len(Strng)-2)+"."
 Else
    Strng="<none>"
 Endif
 Print #TempFile1,Strng
 Case 13
 Strng=Nul
 Strng=Strng+"Spell casting type which requires ingredients:"
 Print #TempFile1,Strng
 Case 14
 TempA=False
 If SpellRecord.SpellFlag And Use.Spell.Type Then
    Strng="use command, "
    TempA=True
 Endif
 If SpellRecord.SpellFlag And Scroll.Spell.Type Then
    Strng=Strng+"read scroll, "
    TempA=True
 Endif
 If SpellRecord.SpellFlag And Cast.Spell.Type Then
    Strng=Strng+"cast spell, "
    TempA=True
 Endif
 If TempA Then
    Strng=Left$(Strng,Len(Strng)-2)+"."
 Else
    Strng="<none>"
 Endif
 Print #TempFile1,Strng
 Case 15
 Strng=Nul
 Strng=Strng+"Spell has offense equation: "
 If SpellRecord.Equation Then
    Strng=Strng+"Yes"
    Print #TempFile1,Strng
 Else
    Strng=Strng+"No"
    Print #TempFile1,Strng
 Endif
 Case 16
 If SpellRecord.Equation Then
    Strng=SpellRecord.SpellEquate
    Strng=Rtrim$(Strng)
    Strng="Equation: "+Strng
    Print #TempFile1,Strng
 Endif
 End Select
ErrExit109a:
 Exit Sub
ErrResume109a:
 Resume ErrExit109a
End Sub
