 Rem File: Cmd142.bas
 Rem Sub: Whatis.Command
 Rem $Include: 'dndbbs.inc'
 Declare Function Strip.Node$(V$)
 On Error Goto Main.Error
 If Chained<>-2 Then
    Local.Mode=True
    User.Linelength=80
    Call Read.Rows(Var)
    User.Pagelength=Var
    Max.Row=Var
    Call Save.Screen2(0)
    Locate Max.Row-1,1,1
    Strng="DNDBBS Command 142 -- Whatis.Command."
    Call IO.O
    ANSIPrefixChar="{"
    Equate.Debug=True
    Date.On = Format$(Now,"mm-dd-yyyy")
    Time.On = Format$(Now,"hh:mm:ss")
    Gosub StatusLineOn
    'Call Whatis.Command (Nul)
    Call Whatis.Command (Command$)
    Gosub StatusLineOff
    Color 7, 0
    Cls
    Call Save.Screen2(-1)
    ' Locate Max.Row,1,1
    If TempX=0 Then TempX=1
    Locate TempX,1,1
    Color 15,0
    Print
    Print "Now exiting Whatis.."
    Color 7,0
    End
 Endif
 Call Whatis.Command ("")
Main.Resume:
 Chain DND.Path+"DNDBBS.EXE"
 End
Main.Error:
 Resume Main.Resume

StatusLineOn:
 Locate Max.Row,1,1
 Color 15,1
 S$ = "Whatis utility v"+Version$+" "+Format$(Now,"mm-dd-yyyy")+" "+Format$(Now,"hh:mm:ss")
 S$ = S$ + Space$(80-Len(S$))
 Print S$;
 Locate Max.Row-1,1,1
 Color 15,0
 Return

StatusLineOff:
 Color 7, 0
 Locate Max.Row,1,1
 Print Space$(80);
 Print "Now exiting Whatis."
 Return

Sub Whatis.Command (Var4$)
 On Local Error Goto Error.Trap28
 If Len(Var4$) Then
    Out2 = Strip.Node$(Var4$)
    If Len(Out2) Then
       Gosub Calc.Equate
       Call More.Prompt
       Exit Sub
    Endif
 Endif
 If Chained=-2 Then
    Gosub Get.Config3
 Else
    Gosub Get.Config4
 Endif
 Do While Lost.Carrier=False
    Graphics.Off=False
    Strng="Equation/formula parse menu."
    Call IO.O
    Graphics.Off=True
    If Option1 Then
       Strng="[1]Equation analysis"
    Else
       Strng="[*]Equation analysis"
    Endif
    Call IO.O
    If Option2 Then
       Strng="[2]Custom equation"
    Else
       Strng="[*]Custom equation"
    Endif
    Call IO.O
    If Option3 Then
       Strng="[3]Custom whatis"
    Else
       Strng="[*]Custom whatis"
    Endif
    Call IO.O
    If Option4 Then
       Strng="[4]Equation help"
    Else
       Strng="[*]Equation help"
    Endif
    Call IO.O
    If Option5 Then
       Strng="[5]Whatis help"
    Else
       Strng="[*]Whatis help"
    Endif
    Call IO.O
    Graphics.Off=False
    No.Input.Out="Q"
    Strng="Enter equation(Q to Quit)? "
    Call IO.I
    If Ucase$(Out2)="Q" Then
       Exit Do
    Endif
    Temp=Int(Val(Out2)+.5)
    Out2=Nul
    Select Case Temp
    Case 1
       If Option1=False Then
          Strng="Command restricted!"
          Call IO.O
       Else
          Do While Lost.Carrier=False
             Graphics.Off=False
             Strng="Equation/formula parse menu."
             Call IO.O
             Graphics.Off=True
             Strng="[1]Monster attack formula"
             Call IO.O
             Strng="[2]User attack formula"
             Call IO.O
             Strng="[3]Monster attack miss equation"
             Call IO.O
             Strng="[4]User attack miss equation"
             Call IO.O
             Strng="[5]Player turn undead equation"
             Call IO.O
             Strng="[6]Player feint equation"
             Call IO.O
             Strng="[7]Player circle equation"
             Call IO.O
             Strng="[8]Player fumble equation"
             Call IO.O
             Strng="[9]User fights hit points formula"
             Call IO.O
             Strng="[10]User psionic attack formula"
             Call IO.O
             Strng="[11]Monster psionic attack formula"
             Call IO.O
             Strng="[12]Constitution roll equation"
             Call IO.O
             Graphics.Off=False
             No.Input.Out="Q"
             Strng="Enter equation(L to List, Q to Quit)? "
             Call IO.I
             If Lcase$(Out2)="l" Then
                Strng="[1]Monster attack formula: "
                If Chained<>-2 Then
                   Strng=Strng+"RND*10+(MHP/10-(SH+AR+BO+HE+TW+AM)/2+MW/2)*XX"
                Else
                   Strng=Strng+Config3(29)
                Endif
                Call IO.O
                Strng="[2]User attack formula: "
                If Chained<>-2 Then
                   Strng=Strng+"(RND*STR+LVL/2)*(XX+PROF/100)-MS/2-MA/2+WE"
                Else
                   Strng=Strng+Config3(30)
                Endif
                Call IO.O
                Strng="[3]Monster attack miss equation: "
                If Chained<>-2 Then
                   Strng=Strng+"DEX/10>RND*10+MLVL*2"
                Else
                   Strng=Strng+Config3(31)
                Endif
                Call IO.O
                Strng="[4]User attack miss equation: "
                If Chained<>-2 Then
                   Strng=Strng+"RND*10+MLVL/10>DEX/2"
                Else
                   Strng=Strng+Config3(32)
                Endif
                Call IO.O
                Strng="[5]Player turn undead equation: "
                If Chained<>-2 Then
                   Strng=Strng+"RND*LVL+2>MLVL"
                Else
                   Strng=Strng+Config3(33)
                Endif
                Call IO.O
                Strng="[6]Player feint equation: "
                If Chained<>-2 Then
                   Strng=Strng+"DEX>RND*5+MLVL/2"
                Else
                   Strng=Strng+Config3(34)
                Endif
                Call IO.O
                Strng="[7]Player circle equation: "
                If Chained<>-2 Then
                   Strng=Strng+"RND*5+LVL>MLVL"
                Else
                   Strng=Strng+Config3(35)
                Endif
                Call IO.O
                Strng="[8]Player fumble equation: "
                If Chained<>-2 Then
                   Strng=Strng+"RND*10+5>DEX*2"
                Else
                   Strng=Strng+Config3(36)
                Endif
                Call IO.O
                Strng="[9]User fights hit points formula: "
                If Chained<>-2 Then
                   Strng=Strng+"(FAT+VIT+MAG)*LVL+STR"
                Else
                   Strng=Strng+Config3(37)
                Endif
                Call IO.O
                Strng="[10]User psionic attack formula: "
                If Chained<>-2 Then
                   Strng=Strng+"(RND*INT+WIS)*(PSIA+XX)"
                Else
                   Strng=Strng+Config3(43)
                Endif
                Call IO.O
                Strng="[11]Monster psionic attack formula: "
                If Chained<>-2 Then
                   Strng=Strng+"(RND*(MHP/10)-PSID)*MPSI"
                Else
                   Strng=Strng+Config3(44)
                Endif
                Call IO.O
                Strng="[12]Constitution roll equation: "
                If Chained<>-2 Then
                   Strng=Strng+"(RND*10+10)+CON/2>20"
                Else
                   Strng=Strng+Config3(45)
                Endif
                Call IO.O
                Call More.Prompt
                Exit Do
             Endif
             If Lcase$(Out2)="q" Then
                Exit Do
             Endif
             Temp=Int(Val(Out2)+.5)
             Out2=Nul
             Select Case Temp
             Case 1
                If Chained<>-2 Then
                   Out2="RND*10+(MHP/10-(SH+AR+BO+HE+TW+AM)/2+MW/2)*XX"
                Else
                   Out2=Config3(Temp+28)
                Endif
             Case 2
                If Chained<>-2 Then
                   Out2="(RND*STR+LVL/2)*(XX+PROF/100)-MS/2-MA/2+WE"
                Else
                   Out2=Config3(Temp+28)
                Endif
             Case 3
                If Chained<>-2 Then
                   Out2="DEX/10>RND*10+MLVL*2"
                Else
                   Out2=Config3(Temp+28)
                Endif
             Case 4
                If Chained<>-2 Then
                   Out2="RND*10+MLVL/10>DEX/2"
                Else
                   Out2=Config3(Temp+28)
                Endif
             Case 5
                If Chained<>-2 Then
                   Out2="RND*LVL+2>MLVL"
                Else
                   Out2=Config3(Temp+28)
                Endif
             Case 6
                If Chained<>-2 Then
                   Out2="DEX>RND*5+MLVL/2"
                Else
                   Out2=Config3(Temp+28)
                Endif
             Case 7
                If Chained<>-2 Then
                   Out2="RND*5+LVL>MLVL"
                Else
                   Out2=Config3(Temp+28)
                Endif
             Case 8
                If Chained<>-2 Then
                   Out2="RND*10+5>DEX*2"
                Else
                   Out2=Config3(Temp+28)
                Endif
             Case 9
                If Chained<>-2 Then
                   Out2="(FAT+VIT+MAG)*LVL+STR"
                Else
                   Out2=Config3(Temp+28)
                Endif
             Case 10
                If Chained<>-2 Then
                   Out2="(RND*INT+WIS)*(PSIA+XX)"
                Else
                   Out2=Config3(Temp+33)
                Endif
             Case 11
                If Chained<>-2 Then
                   Out2="(RND*(MHP/10)-PSID)*MPSI"
                Else
                   Out2=Config3(Temp+33)
                Endif
             Case 12
                If Chained<>-2 Then
                   Out2="(RND*10+10)+CON/2>20"
                Else
                   Out2=Config3(Temp+33)
                Endif
             End Select
             If Len(Out2) Then
                Gosub Calc.Equate
                Call More.Prompt
             Endif
          Loop
       Endif
    Case 2
       If Option2=False Then
          Strng="Command restricted!"
          Call IO.O
       Else
          Strng="Enter equation(Q to Quit):"
          Call IO.O
          Do While Lost.Carrier=False
             Strng="?"
             Call IO.I
             Out2=Ucase$(Out2)
             If Out2="Q" Then
                Out2=Nul
                Exit Do
             Endif
             Gosub Calc.Equate
          Loop
       Endif
    Case 3
       If Option3=False Then
          Strng="Command restricted!"
          Call IO.O
       Else
          Strng="Enter whatis(Q to Quit):"
          Call IO.O
          Do While Lost.Carrier=False
             Strng="?"
             Call IO.I
             If Len(Out2) Then
                If Ucase$(Out2)="Q" Then
                   Out2=Nul
                   Exit Do
                Endif
                Strng=Out2
                Call Convert.String
                Call Convert.ANSI(False,VarQ,VarR)
                If Rtrim$(Strng)<>"" Then
                   Graphics.On=True
                   Call IO.O
                   Graphics.On=False
                Endif
             Endif
          Loop
       Endif
    Case 4
       If Option4=False Then
          Strng="Command restricted!"
          Call IO.O
       Else
          Allow.Break=True
          Call Out.File("EQUATE.HLP","-1")
          Call IO.O
       Endif
    Case 5
       If Option5=False Then
          Strng="Command restricted!"
          Call IO.O
       Else
          Allow.Break=True
          Call Out.File("OUTFILE.LST","-1")
          Call IO.O
       Endif
    Case Else
       Strng="Unknown command."
       Call IO.O
    End Select
 Loop
 Exit Sub

Calc.Equate:
 If Len(Out2) Then
    Call Equate(Temp#)
    If Temp#=DFalse Then
       Strng="False"
    Else
       If Temp#=DTrue Then
          Strng="True"
       Else
          Strng=Str$(Temp#)
       Endif
    Endif
    Strng=Out2+" = "+Ltrim$(Strng)
 Else
    Strng="<nul>"
 Endif
 Call IO.O
 Return

Get.Config3:
 VarX=0
 Option1=-1
 Option2=-1
 Option3=-1
 Option4=-1
 Option5=-1
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Goto Next.Read1
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD142]" Then
       Do
          VarX=VarX+1
          If VarX>Options.Lines Then
             Goto Next.Read1
             Return
          Endif
          Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
          If Ucase$(Var$)="[END]" Then
             Goto Next.Read1
             Return
          Endif
          Var=Instr(Var$,"=")
          If Var Then
             Var2$=Lcase$(Ltrim$(Rtrim$(Left$(Var$,Var-1))))
             Var3$=Lcase$(Ltrim$(Rtrim$(Mid$(Var$,Var+1))))
             Gosub Parse.Options1
          Endif
       Loop
    Endif
 Loop
 Return

Next.Read1:
 Close #TempFile1
 Filename$=DND.Path+"CMD142.CFG"
 If Dir$(Filename$)="" Then
    Return
 Endif
 Open Filename$ For Input As #TempFile1
 Do
    If Eof(TempFile1) Then
       Exit Do
    Endif
    Line Input #TempFile1, Var$
    Var$=Ltrim$(Rtrim$(Var$))
    If Left$(Var$,1)<>";" Then
       VarX$=UserRecord.CodeName
       VarX$=Rtrim$(VarX$)
       VarX$=Ucase$(VarX$)
       If Ucase$(Var$)="["+VarX$+"]" Then
          VarZ=0
          Option1=-1
          Option2=-1
          Option3=-1
          Option4=-1
          Option5=-1
          Do
             If Eof(TempFile1) Then
                Exit Do
             Endif
             Line Input #TempFile1, Var$
             If Ucase$(Var$)="[END]" Then
                Return
             Endif
             Var=Instr(Var$,"=")
             If Var Then
                Var2$=Ltrim$(Rtrim$(Left$(Var$,Var-1)))
                Var3$=Ltrim$(Rtrim$(Mid$(Var$,Var+1)))
                Gosub Parse.Options1
             Endif
          Loop
       Endif
    Endif
 Loop
 Return

Parse.Options1:
 If Left$(Var2$,12)="allow.whatis" Then
    VarZ2=True
    Select Case Var3$
    Case "0", "false", "off"
       VarZ2=False
    Case "-1", "true", "on"
       VarZ2=True
    End Select
    VarQ=Int(Val(Mid$(Var2$,13))+.5)
    Select Case VarQ
    Case 1
       Option1=VarZ2
    Case 2
       Option2=VarZ2
    Case 3
       Option3=VarZ2
    Case 4
       Option4=VarZ2
    Case 5
       Option5=VarZ2
    End Select
 Endif
 Return

Get.Config4:
 VarX=0
 Option1=-1
 Option2=-1
 Option3=-1
 Option4=-1
 Option5=-1
 DND.Path=Environ$("DNDBBS")
 If DND.Path<>Nul Then
    If Right$(DND.Path,1)<>"\" Then
       DND.Path=DND.Path+"\"
    Endif
 Endif
 Call Get.Node
 Filename=DND.Path+"option"+NodeX+".cfg"
 Close #Tempfile1
 If Dir$(Filename)=Nul Then Return
 Open Filename For Input As #TempFile1
 Do Until Eof(TempFile1) 
    Line Input #Tempfile1, Var$
    Var$=Ltrim$(Rtrim$(var$))
    If Ucase$(Var$)="[CMD142]" Then
       Do Until Eof(TempFile1)
          Line Input #TempFile1, Var$
          Var$=Ltrim$(Rtrim$(Var$))
          If Ucase$(Var$)="[END]" Then
             Return
          Endif
          Var=Instr(Var$,"=")
          If Var Then
             Var2$=Lcase$(Ltrim$(Rtrim$(Left$(Var$,Var-1))))
             Var3$=Lcase$(Ltrim$(Rtrim$(Mid$(Var$,Var+1))))
             Gosub Parse.Options1
          Endif
       Loop
    Endif
 Loop
 Return
Error.Resume28:
 Exit Sub
Error.Trap28:
 Strng="Error:"+Str$(Err)
 Call IO.O
 Resume Error.Resume28
End Sub

Sub Get.Node
 On Local Error Goto Error.Trap62z
 NodeX=Nul
 Var$=Command$
 Var$=Ltrim$(Rtrim$(Var$))
 If Instr(Var$,"/N:") Then
    Var$=Mid$(Var$,Instr(Var$,"/N:")+3)
    If Left$(Var$,1)>="A" And Left$(Var$,1)<="Z" Then
       NodeX=Left$(Var$,1) ' A-Z
    Endif
    If Left$(Var$,1)>="0" And Left$(Var$,1)<="9" Then
       If Mid$(Var$,2,1)>="0" And Mid$(Var$,2,1)<="9" Then
          Var$=Left$(Var$,2)
          If Val(Var$)>=10 And Val(Var$)<=99 Then
             NodeX=Var$ ' 10-99
          Endif
       Else
          NodeX=Left$(Var$,1) ' 0-9
       Endif
    Endif
 Endif
Error.Trap62z:
 Exit Sub
End Sub

Function Strip.Node$(Var$)
 On Local Error Goto Error.Trap62y
 VarX$=Ucase$(Var$)
 VarX=Instr(VarX$,"/N:")
 If VarX Then
    Var2$=Mid$(VarX$,VarX+3,1)
    If Var2$>="0" And Var2$<="9" Then
       Var3$=Mid$(VarX$,VarX+4,1)
       If Var3$>="0" And Var3$<="9" Then
          Strip.Node$=Left$(Var$,VarX-1)+Mid$(Var$,VarX+5) ' 10-99
       Else
          Strip.Node$=Left$(Var$,VarX-1)+Mid$(Var$,VarX+4) ' 0-9
       Endif
    Else
       If Var2$>="A" And Var2$<="Z" Then
          Strip.Node$=Left$(Var$,VarX-1)+Mid$(Var$,VarX+4) ' A-Z
       Endif
    Endif
 Else
    Strip.Node$ = Var$
 Endif
Error.Trap62y:
 Exit Function
End Function

Sub Read.Rows(Var)
 On Local Error Goto Error.Trap62x
 Temp1=50
 Locate 50,1,0
 Var=50
 Exit Sub
Next.Trap1:
 Temp1=43
 Locate 43,1,0
 Var=43
 Exit Sub
Next.Trap2:
 Temp1=25
 Locate 25,1,0
 Var=25
 Exit Sub
Next.Trap3:
 Var=12
Error.Resume62x:
 Exit Sub
Error.Trap62x:
 If Temp1=50 Then
    Resume Next.Trap1
 Endif
 If Temp1=43 Then
    Resume Next.Trap2
 Endif
 If Temp1=25 Then
    Resume Next.Trap3
 Endif
 Resume Error.Resume62x
End Sub

Sub Save.Screen2(Var)
 On Local Error Goto Error.Trap62
 If Var=False Then
    VarX3=(Max.Row-1)*80+80
    Redim Temp.ArrayY(VarX3) As Long
    Redim Temp.ArrayZ(VarX3) As Double
    For Var1=1 To Max.Row
       For Var2=1 To 80
          TempZ1=Screen(Var1,Var2)
          TempZ2=Screen(Var1,Var2,1)
          VarX2=(Var1-1)*80+Var2
          Temp.ArrayY(VarX2)=TempZ1
          Temp.ArrayZ(VarX2)=TempZ2
       Next
    Next
 Else
    Cls
    For VarX=Max.Row To 1 Step -1
       For VarY=1 To 80
          VarX2=(VarX-1)*80+VarY
          If Temp.ArrayY(VarX2)<>32 Then
             Goto Next.Line
          Endif
       Next
    Next
Next.Line:
    TempX=VarX
    For Var1=1 To VarX ' Max.Row
       For Var2=1 To 80
          VarX2=(Var1-1)*80+Var2
          VarB=Int(Temp.ArrayZ(VarX2)/16)
          VarF=Temp.ArrayZ(VarX2) Mod 16
          TempZ1=Temp.ArrayY(VarX2)
          Locate Var1,Var2,0
          Color VarF,VarB
          Print Chr$(TempZ1);
       Next
    Next
 Endif
Error.Resume62:
 Exit Sub
Error.Trap62:
 Resume Error.Resume62
End Sub
