 Rem File: Editcmd5 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,"5")
    If Var=False Then
       Call Terminate.Program
       End
    Endif
 Endif
 Call Edit.Room.Links
MainExit0:
 End
ErrMain0:
 Resume MainExit0
 End

Sub Edit.Room.Links
 On Local Error Goto ErrResume21
 Call Edit.Status.Line
 Do While Lost.Carrier=False
    If TempC=False Then
       Graphics.Off=False
       Strng="Roomlink Edit utility v"+Left$(Version$,4)+" menu:"
       Call IO.O
       Graphics.Off=True
       Strng=RT$(169,"[A]")+"dd link"
       Call IO.O
       Strng=RT$(170,"[C]")+"heck links"
       Call IO.O
       Strng=RT$(171,"[D]")+"elete link"
       Call IO.O
       Strng=RT$(172,"[L]")+"ist links"
       Call IO.O
       If Local.Mode Then
          Strng=RT$(585,"[P]")+"rint links"
          Call IO.O
       Endif
       Strng=RT$(173,"[S]")+"earch links"
       Call IO.O
       Strng=RT$(174,"[X]")+"Square links"
       Call IO.O
       Strng=RT$(175,"[Y]")+"Diamond links"
       Call IO.O
       Graphics.Off=False
    Endif
    Strng="Room link edit option(q to quit)? "
    Line.Length=TempD
    No.Input.Out="Q"
    Call IO.I
    Select Case Ucase$(Out2)
    Case "A"
       If RT$(169,"[A]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Change.Link(True)
       Endif
    Case "C"
       If RT$(170,"[C]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Check.Links
       Endif
    Case "D"
       If RT$(171,"[D]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Change.Link(False)
       Endif
    Case "L"
       If RT$(172,"[L]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call List.Links
       Endif
    Case "S"
       If RT$(173,"[S]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Search.Links
       Endif
    Case "X"
       If RT$(174,"[X]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Link.Squares
       Endif
    Case "Y"
       If RT$(175,"[Y]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Link.Diamonds
       Endif
    Case "P"
       If Local.Mode Then
          If RT$(585,"[P]")="[*]" Then
             Strng="Command restricted.."
             Call IO.O
          Else
             Call Print.Links
          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
ErrExit21:
 Exit Sub
ErrResume21:
 Resume ErrExit21
End Sub

Sub Change.Link(TempX)
 On Local Error Goto ErrResume22
 Var3!=Lof(RoomFile)/RoomRecLen
 Strng="Room number to link"
 Call Get.Record.Range2(SFalse,Var3!,Var2!)
 If Var2!=SFalse Then
    Exit Sub
 Endif
 Strng="Direction(N,E,S,W,NE,SE,SW,NW,U,D,I,O,1,2)? "
 Call IO.I
 Select Case Ucase$(Out2)
 Case "N"
    Temp7=1
 Case "E"
    Temp7=2
 Case "S"
    Temp7=3
 Case "W"
    Temp7=4
 Case "NE"
    Temp7=5
 Case "SE"
    Temp7=6
 Case "SW"
    Temp7=7
 Case "NW"
    Temp7=8
 Case "U"
    Temp7=9
 Case "D"
    Temp7=10
 Case "I"
    Temp7=11
 Case "O"
    Temp7=12
 Case "1"
    Temp7=13
 Case "2"
    Temp7=14
 Case Else
    Temp7=False
 End Select
 If Temp7=False Then
    Strng="Unknown direction."
    Call IO.O
    Exit Sub
 Endif
 If TempX=False Then
    Call Read.Record(RoomFile,Var2!)
    RoomRecord.Direct(Temp7)=SFalse
    If Temp7=13 Then
       RoomRecord.Custom1=Nul
    Endif
    If Temp7=14 Then
       RoomRecord.Custom2=Nul
    Endif
    Call Write.Record(RoomFile,Var2!)
    Strng="Link removed."
    Call IO.O
    Exit Sub
 Endif
 Strng="Link to which room number"
 Call Get.Record.Range2(SFalse,Var3!,Temp!)
 If Temp!=SFalse Then
    Exit Sub
 Endif
 Call Read.Record(RoomFile,Var2!)
 RoomRecord.Direct(Temp7)=Temp!
 Call Write.Record(RoomFile,Var2!)
 Strng="Room"+Str$(Var2!)+" linked to"+Str$(Temp!)+"."
 Call IO.O
 If Temp7=13 Then
    Strng="Enter custom direction: "
    Call IO.I
    RoomRecord.Custom1=Ucase$(Out2)
    Call Write.Record(RoomFile,Var2!)
    Exit Sub
 Endif
 If Temp7=14 Then
    Strng="Enter custom direction: "
    Call IO.I
    RoomRecord.Custom2=Ucase$(Out2)
    Call Write.Record(RoomFile,Var2!)
    Exit Sub
 Endif
 Strng="Link back to room"+Str$(Var2!)+"(y/n)? "
 No.Input.Out="N"
 Line.Length=TempD
 Call IO.I
 If Yes=False Then
    Exit Sub
 Endif
 Call Find.Back.Link
 Call Read.Record(RoomFile,Temp!)
 RoomRecord.Direct(Temp8)=Var2!
 Call Write.Record(RoomFile,Temp!)
 Strng="Room"+Str$(Temp!)+" linked back to"+Str$(Var2!)+"."
 Call IO.O
ErrExit22:
 Exit Sub
ErrResume22:
 Resume ErrExit22
End Sub

Sub Check.Links
 On Local Error Goto ErrResume23x
 Strng="Check missing links(y/n)?"
 Call IO.I
 If Yes Then
    Strng="Checking room links.."
    Call IO.O
    Temp1 = False
    Temp2 = False
    FOR Var! = 1! TO LOF(RoomFile) / RoomRecLen
       FOR TempZ = 1 TO 8
          Call Read.Record(RoomFile, Var!)
          Var1! = RoomRecord.Direct(TempZ)
          IF Var1! > 0! And Var1! <= Lof(RoomFile)/RoomRecLen THEN
             Call Read.Record(RoomFile, Var1!)
             GOSUB FindBackLink
             IF Temp4 THEN
                Var2! = RoomRecord.Direct(Temp4)
                IF Var2! <> Var! THEN
                   Strng = "Room#" + STR$(Var!) + ": "
                   Strng = Strng + Lcase$(Rtrim$(Direction(TempZ)))
                   Call IO.O
                   Temp2 = True
                   Temp1 = Temp1 + 1
                   If Temp1>=User.Pagelength-2 Then
                      Temp1 = False
                      Call More.Prompt
                   Endif
                END IF
             END IF
          END IF
       NEXT
    NEXT
    If Temp2 = False Then
       Strng= "No bad links found."
       Call IO.O
       Call More.Prompt
    Else
       If Temp1 Then
          Call More.Prompt
       Endif
    Endif
 Endif
 Strng="Check custom links(y/n)?"
 Call IO.I
 If Yes Then
    Strng="Enter node number(<enter>,0-9,A-Z,10-99)?"
    Call IO.I
    FileName=Nul
    Select Case Len(Out2)
    Case 0
       FileName="DND"
    Case 1
       Select Case Ucase$(Out2)
       Case "0" To "9"
          FileName="DND"+Ucase$(Out2)
       Case "A" To "Z"
          FileName="DND"+Ucase$(Out2)
       End Select
    Case 2
       VarX=Int(Val(Out2))
       If VarX>=10 And VarX<=99 Then
          FileName="DND"+Mid$(Str$(VarX),2)
       Endif
    End Select
    If FileName=Nul Then
       Strng="Filename not found."
       Call IO.O
       Exit Sub
    Endif
    FileName=DND.Path+FileName+".CFG"
    If Dir$(FileName)=Nul Then
       Strng="Filename '"+Filename+"' not found."
       Call IO.O
       Exit Sub
    Endif
    Close #TempFile1
    Open FileName For Input Shared As #TempFile1
    Temp3=MaxUserCommands*3
    Redim Temp.ArrayS(1 To Temp3) As String
    Temp3=False
    For Temp1=1 To MaxConfigArray1
       Input #TempFile1,Var!
    Next
    For Temp1=1 To MaxConfigArray2
       Input #TempFile1,Var%
    Next
    For Temp1=1 To MaxConfigArray3
       Line Input #TempFile1,Var$
       Select Case Temp1
       Case 9 ' DM command
          Var1$=Rtrim$(Var$)
       Case 78 ' node command
          Var2$=Rtrim$(Var$)
       Case 79 ' Sysop command
          Var3$=Rtrim$(Var$)
       Case 85 ' ANSI prefix
          Var4$=Rtrim$(Var$)
       End Select
    Next
    For Temp1=1 To 40
       Input #TempFile1,Var%
    Next
    For Temp1=1 To 87
       Line Input #TempFile1,Var$
    Next
    For Temp1=1 To MaxUserCommands
       Line Input #TempFile1,Var$
       For Temp2=1 To 3
          Line Input #TempFile1,Var$
          If Var$="<>" Or Rtrim$(Var$)=Nul Then
             Eat$ = Nul
          Else
             Temp3=Temp3+1
             Temp.ArrayS(Temp3)=Var$
          Endif
       Next
       For Temp2=1 To 15
          Input #TempFile1,Var%
       Next
    Next
    Close #TempFile1
    Strng="Checking custom links.."
    Call IO.O
    Temp1 = False
    Temp2 = False
    FOR Var! = 1! TO LOF(RoomFile) / RoomRecLen
       Call Read.Record(RoomFile, Var!)
       Var$=RoomRecord.Custom1
       Var$=Ucase$(Rtrim$(Var$))
       For Temp4=1 To Temp3
          If Var$=Ucase$(Temp.ArrayS(Temp4)) Then
             Strng="Custom direction1 '"+Var$+"' in room#"+ _
             Mid$(Str$(Var!),2)+" conflicts with command."
             Gosub Display.Line
          Endif
       Next
       If Len(Var1$) Then
          If Left$(Var$,Len(Var1$))=Var1$ Then
             Strng="Custom direction1 '"+Var$+"' in room#"+ _
             Mid$(Str$(Var!),2)+" conflicts with "+Var1$+" prefix."
             Gosub Display.Line
          Endif
       Endif
       If Len(Var2$) Then
          If Left$(Var$,Len(Var2$))=Var2$ Then
             Strng="Custom direction1 '"+Var$+"' in room#"+ _
             Mid$(Str$(Var!),2)+" conflicts with "+Var2$+" prefix."
             Gosub Display.Line
          Endif
       Endif
       If Len(Var3$) Then
          If Left$(Var$,Len(Var3$))=Var3$ Then
             Strng="Custom direction1 '"+Var$+"' in room#"+ _
             Mid$(Str$(Var!),2)+" conflicts with "+Var3$+" prefix."
             Gosub Display.Line
          Endif
       Endif
       If Len(Var4$) Then
          If Instr(Var$,Var4$) Then
             Strng="Custom direction1 '"+Var$+"' in room#"+ _
             Mid$(Str$(Var!),2)+" conflicts with "+Var4$+" prefix."
             Gosub Display.Line
          Endif
       Endif
       If Instr(Var$,"[") Then
          Strng="Custom direction1 '"+Var$+"' in room#"+ _
          Mid$(Str$(Var!),2)+" conflicts with [ prefix."
          Gosub Display.Line
       Endif
       Var$=RoomRecord.Custom2
       Var$=Ucase$(Rtrim$(Var$))
       For Temp4=1 To Temp3
          If Var$=Ucase$(Temp.ArrayS(Temp4)) Then
             Strng="Custom direction2 '"+Var$+"' in room#"+ _
             Mid$(Str$(Var!),2)+" conflicts with command."
             Gosub Display.Line
          Endif
       Next
       If Len(Var1$) Then
          If Left$(Var$,Len(Var1$))=Var1$ Then
             Strng="Custom direction2 '"+Var$+"' in room#"+ _
             Mid$(Str$(Var!),2)+" conflicts with "+Var1$+" prefix."
             Gosub Display.Line
          Endif
       Endif
       If Len(Var2$) Then
          If Left$(Var$,Len(Var2$))=Var2$ Then
             Strng="Custom direction2 '"+Var$+"' in room#"+ _
             Mid$(Str$(Var!),2)+" conflicts with "+Var2$+" prefix."
             Gosub Display.Line
          Endif
       Endif
       If Len(Var3$) Then
          If Left$(Var$,Len(Var3$))=Var3$ Then
             Strng="Custom direction2 '"+Var$+"' in room#"+ _
             Mid$(Str$(Var!),2)+" conflicts with "+Var3$+" prefix."
             Gosub Display.Line
          Endif
       Endif
       If Len(Var4$) Then
          If Instr(Var$,Var4$) Then
             Strng="Custom direction2 '"+Var$+"' in room#"+ _
             Mid$(Str$(Var!),2)+" conflicts with "+Var4$+" prefix."
             Gosub Display.Line
          Endif
       Endif
       If Instr(Var$,"[") Then
          Strng="Custom direction2 '"+Var$+"' in room#"+ _
          Mid$(Str$(Var!),2)+" conflicts with [ prefix."
          Gosub Display.Line
       Endif
    Next
    If Temp2 = False Then
       Strng= "No bad custom directions found."
       Call IO.O
       Call More.Prompt
    Else
       If Temp1 Then
          Call More.Prompt
       Endif
    Endif
    Redim Temp.ArrayS(1 To 1) As String
 Endif
 Exit Sub
Display.Line:
 Call IO.O
 Temp2 = True
 Temp1 = Temp1 + 1
 If Temp1>=User.Pagelength-2 Then
    Temp1 = False
    Call More.Prompt
 Endif
 Return
FindBackLink:
 SELECT CASE TempZ
 CASE 1
    Temp4 = 3
 CASE 2
    Temp4 = 4
 CASE 3
    Temp4 = 1
 CASE 4
    Temp4 = 2
 CASE 5
    Temp4 = 7
 CASE 6
    Temp4 = 8
 CASE 7
    Temp4 = 5
 CASE 8
    Temp4 = 6
 CASE 9
    Temp4 = 10
 CASE 10
    Temp4 = 9
 CASE 11
    Temp4 = 12
 CASE 12
    Temp4 = 11
 CASE ELSE
    Temp4 = False
 END SELECT
 RETURN
ErrExit23x:
 Exit Sub
ErrResume23x:
 Strng="Error"+Str$(Err)+" "+FileName
 Call IO.O
 Resume ErrExit23x
End Sub

Sub List.Links
 On Local Error Goto ErrResume23
 Var3!=Lof(RoomFile)/RoomRecLen
 Call Get.Record.Range(Var1!,Var2!,Var3!)
 Allow.Break=True
 Break=False
 Continuous=False
 Temp6=False
 For Temp!=Var1! To Var2!
    Call Read.Record(RoomFile,Temp!)
    For VarQ=1 To 5
       Call Display.Link(VarQ)
       If Break Then
	  Exit For
       Endif
    Next
    If Break Then
       Exit For
    Endif
    Temp6=Temp6+1
    If Temp6>=4 Then
       Temp6=False
       If Continuous=False Then
	  Call More.Prompt
	  If No Or Quit Then
	     Exit For
	  Endif
       Endif
    Endif
 Next
 Allow.Break=False
 Break=False
 If Temp6 Then
    Call More.Prompt
 Endif
ErrExit23:
 Exit Sub
ErrResume23:
 Resume ErrExit23
End Sub

Sub Print.Links
 On Local Error Goto ErrResume23a
 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
    Var3!=Lof(RoomFile)/RoomRecLen
    Call Get.Record.Range(Var1!,Var2!,Var3!)
    Temp6=False
    For Temp!=Var1! To Var2!
       Call Read.Record(RoomFile,Temp!)
       For VarQ=1 To 4
          Call Print.Link(VarQ)
       Next
       Temp6=Temp6+1
       If Temp6>=10 Then
          Temp6=False
          Print #TempFile1,Chr$(12);
       Endif
    Next
    If Temp6 Then
       Print #TempFile1,Chr$(12);
    Endif
 Endif
ErrExit23a:
 Close #TempFile1
 Exit Sub
ErrResume23a:
 Resume ErrExit23a
End Sub

Sub Display.Link(Var)
 On Local Error Goto ErrResume24
 Graphics.Off=True
 Select Case Var
 Case 1
 Strng="Room number"+Str$(Temp!)+":"
 Call IO.O
 Case 2
 Strng=Nul
 For Temp3=1 To 4
    Out2=Direction(Temp3)+Str$(RoomRecord.Direct(Temp3))
    Strng=Strng+Out2+Space$(20-Len(Out2))
 Next
 Strng=Rtrim$(Strng)
 Call IO.O
 Case 3
 Strng=Nul
 For Temp3=5 To 8
    Out2=Direction(Temp3)+Str$(RoomRecord.Direct(Temp3))
    Strng=Strng+Out2+Space$(20-Len(Out2))
 Next
 Strng=Rtrim$(Strng)
 Call IO.O
 Case 4
 Strng=Nul
 For Temp3=9 To 12
    Out2=Direction(Temp3)+Str$(RoomRecord.Direct(Temp3))
    Strng=Strng+Out2+Space$(20-Len(Out2))
 Next
 Strng=Rtrim$(Strng)
 Call IO.O
 Case 5
 Strng="Custom1: "
 Var$=Rtrim$(RoomRecord.Custom1)
 If Var$=String$(12,Chr$(0)) Then
    Var$=Nul
 Endif
 If Len(Var$) Then
    If RoomRecord.Direct(13)>SFalse Then
       Strng=Strng+Lcase$(Var$)+" ="+Str$(RoomRecord.Direct(13))
    Else
       Strng=Strng+Lcase$(Var$)+" = <none>"
    Endif
 Else
    Strng=Strng+"<none>"
 Endif
 Strng=Strng+" Custom2: "
 Var$=Rtrim$(RoomRecord.Custom2)
 If Var$=String$(12,Chr$(0)) Then
    Var$=Nul
 Endif
 If Len(Var$) Then
    If RoomRecord.Direct(14)>SFalse Then
       Strng=Strng+Lcase$(Var$)+" ="+Str$(RoomRecord.Direct(14))
    Else
       Strng=Strng+Lcase$(Var$)+" = <none>"
    Endif
 Else
    Strng=Strng+"<none>"
 Endif
 Call IO.O
 End Select
ErrExit24:
 Exit Sub
ErrResume24:
 Resume ErrExit24
End Sub

Sub Print.Link(Var)
 On Local Error Goto ErrResume24a
 Graphics.Off=True
 Select Case Var
 Case 1
 Strng="Room number"+Str$(Temp!)+":"
 Print #TempFile1,Strng
 Case 2
 Strng=Nul
 For Temp3=1 To 4
    Out2=Direction(Temp3)+Str$(RoomRecord.Direct(Temp3))
    Strng=Strng+Out2+Space$(20-Len(Out2))
 Next
 Strng=Rtrim$(Strng)
 Print #TempFile1,Strng
 Case 3
 Strng=Nul
 For Temp3=5 To 8
    Out2=Direction(Temp3)+Str$(RoomRecord.Direct(Temp3))
    Strng=Strng+Out2+Space$(20-Len(Out2))
 Next
 Strng=Rtrim$(Strng)
 Print #TempFile1,Strng
 Case 4
 Strng=Nul
 For Temp3=9 To 12
    Out2=Direction(Temp3)+Str$(RoomRecord.Direct(Temp3))
    Strng=Strng+Out2+Space$(20-Len(Out2))
 Next
 Strng=Rtrim$(Strng)
 Print #TempFile1,Strng
 Strng=Nul
 Var$=Rtrim$(RoomRecord.Custom1)
 If Var$=String$(12,Chr$(0)) Then
    Var$=Nul
 Endif
 If Len(Var$) Then
    If RoomRecord.Direct(13)>SFalse Then
       Strng="Custom1: "+Lcase$(Var$)+" ="+Str$(RoomRecord.Direct(13))+" "
    Endif
 Endif
 Var$=Rtrim$(RoomRecord.Custom2)
 If Var$=String$(12,Chr$(0)) Then
    Var$=Nul
 Endif
 If Len(Var$) Then
    If RoomRecord.Direct(14)>SFalse Then
       Strng=Strng+"Custom2: "+Lcase$(Var$)+" ="+Str$(RoomRecord.Direct(14))
    Endif
 Endif
 If Len(Strng) Then
    Print #TempFile1,Strng
 Endif
 End Select
ErrExit24a:
 Exit Sub
ErrResume24a:
 Resume ErrExit24a
End Sub

Sub Link.Squares
 On Local Error Goto ErrResume25
 Var3!=Lof(RoomFile)/RoomRecLen
 Strng="Room number to square link"
 Call Get.Record.Range2(SFalse,Var3!,Var2!)
 If Var2!=SFalse Then
    Exit Sub
 Endif
 Restore Square.Data
 VarN=False
 For VarX=1 To 8
    Read Var1,Var2,Var3,Var4
    Call Read.Record(RoomFile,Var2!)
    Do
       VarX!=RoomRecord.Direct(Var1)
       If VarX!<=SFalse Or VarX!>Lof(RoomFile)/RoomRecLen Then
          Exit Do
       Endif
       Call Read.Record(RoomFile,VarX!)
       VarY!=RoomRecord.Direct(Var2)
       If VarY!<=SFalse Or VarY!>Lof(RoomFile)/RoomRecLen Then
          Exit Do
       Endif
       Call Read.Record(RoomFile,VarY!)
       VarZ!=RoomRecord.Direct(Var3)
       If VarZ!<=SFalse Or VarZ!>Lof(RoomFile)/RoomRecLen Then
          Exit Do
       Endif
       Call Read.Record(RoomFile,VarZ!)
       Temp7=Var4
       Call Find.Back.Link
       If RoomRecord.Direct(Var4)=SFalse Then
          Call Read.Record(RoomFile,Var2!)
          If RoomRecord.Direct(Temp8)=SFalse Then
             Call Read.Record(RoomFile,VarZ!)
             RoomRecord.Direct(Var4)=Var2!
             Call Write.Record(RoomFile,VarZ!)
             Call Read.Record(RoomFile,Var2!)
             RoomRecord.Direct(Temp8)=VarZ!
             Call Write.Record(RoomFile,Var2!)
             VarN=VarN+1
          Endif
       Endif
       Exit Do
    Loop
 Next
 Select Case VarN
 Case False
    Strng="No square room links found."
 Case Else
    Strng=Rtrim$(Numeral(VarN))
    Mid$(Strng,1,1)=Ucase$(Mid$(Strng,1,1))
    If VarN=1 Then
       Strng=Strng+" square room linked."
    Else
       Strng=Strng+" square rooms linked."
    Endif
 End Select
 Call IO.O
ErrExit25:
 Exit Sub
ErrResume25:
 Resume ErrExit25
End Sub

Sub Link.Diamonds
 On Local Error Goto ErrResume25a
 Var3!=Lof(RoomFile)/RoomRecLen
 Strng="Room number to square link"
 Call Get.Record.Range2(SFalse,Var3!,Var2!)
 If Var2!=SFalse Then
    Exit Sub
 Endif
 Restore Diamond.Data
 VarN=False
 For VarX=1 To 8
    Read Var1,Var2,Var3,Var4
    Call Read.Record(RoomFile,Var2!)
    Do
       VarX!=RoomRecord.Direct(Var1)
       If VarX!<=SFalse Or VarX!>Lof(RoomFile)/RoomRecLen Then
          Exit Do
       Endif
       Call Read.Record(RoomFile,VarX!)
       VarY!=RoomRecord.Direct(Var2)
       If VarY!<=SFalse Or VarY!>Lof(RoomFile)/RoomRecLen Then
          Exit Do
       Endif
       Call Read.Record(RoomFile,VarY!)
       VarZ!=RoomRecord.Direct(Var3)
       If VarZ!<=SFalse Or VarZ!>Lof(RoomFile)/RoomRecLen Then
          Exit Do
       Endif
       Call Read.Record(RoomFile,VarZ!)
       Temp7=Var4
       Call Find.Back.Link
       If RoomRecord.Direct(Var4)=SFalse Then
          Call Read.Record(RoomFile,Var2!)
          If RoomRecord.Direct(Temp8)=SFalse Then
             Call Read.Record(RoomFile,VarZ!)
             RoomRecord.Direct(Var4)=Var2!
             Call Write.Record(RoomFile,VarZ!)
             Call Read.Record(RoomFile,Var2!)
             RoomRecord.Direct(Temp8)=VarZ!
             Call Write.Record(RoomFile,Var2!)
             VarN=VarN+1
          Endif
       Endif
       Exit Do
    Loop
 Next
 Select Case VarN
 Case False
    Strng="No diamond room links found."
 Case Else
    Strng=Rtrim$(Numeral(VarN))
    Mid$(Strng,1,1)=Ucase$(Mid$(Strng,1,1))
    If VarN=1 Then
       Strng=Strng+" diamond room linked."
    Else
       Strng=Strng+" diamond rooms linked."
    Endif
 End Select
 Call IO.O
ErrExit25a:
 Exit Sub
ErrResume25a:
 Resume ErrExit25a
End Sub

Sub Find.Back.Link
 On Local Error Goto ErrResume26
 Select Case Temp7
 Case 1
    Temp8=3
 Case 2
    Temp8=4
 Case 3
    Temp8=1
 Case 4
    Temp8=2
 Case 5
    Temp8=7
 Case 6
    Temp8=8
 Case 7
    Temp8=5
 Case 8
    Temp8=6
 Case 9
    Temp8=10
 Case 10
    Temp8=9
 Case 11
    Temp8=12
 Case 12
    Temp8=11
 End Select
ErrExit26:
 Exit Sub
ErrResume26:
 Resume ErrExit26
End Sub

Sub Search.Links
 On Local Error Goto ErrResume62
 VarZ1=0
 Do While Lost.Carrier=False
    Var3!=SFalse
    Var4!=SFalse
    Var3$=Nul
    Do While Lost.Carrier=False
       Graphics.Off=True
       If TempC=False Then
          Strng="[A]room link"
          If Var3! Then
             Strng=Strng+Space$(30-Len(Strng))
             Strng=Strng+"("+Mid$(Str$(Var3!),2)+")"
          Endif
          If Len(Var3$) Then
             Strng=Strng+" ["+Var3$+"]"
          Endif
          Call IO.O
          Strng="[B]room link and back"
          If Var4! Then
             Strng=Strng+Space$(30-Len(Strng))
             Strng=Strng+"("+Mid$(Str$(Var4!),2)+")"
          Endif
          Call IO.O
          Graphics.Off=False
       Endif
       Strng="Room link 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="Room link number? "
          Call IO.I
          Var3!=Int(Val(Out2))
          Strng="Custom room link? "
          Call IO.I
          If Len(Out2) Then
             Var3$=Out2
          Endif
       Case "B"
          Strng="Room link number? "
          Call IO.I
          Var4!=Int(Val(Out2))
       Case "S"
          Allow.Break=True
          Break=False
          Continuous=False
          Var!=Lof(RoomFile)/RoomRecLen
          Call Get.Record.Range(Var1!,Var2!,Var!)
          If Len(Var3$) Then
             No=False
             Quit=False
             Call Find.Custom2(Var,Var3$)
             If No Or Quit Then
                Exit Do
             Endif
             If Var Then
                Strng="Continue searching(y/n)? "
                Call IO.I
                If No Then
                   Exit Do
                Endif
             Endif
          Endif
          VarX=0
          If Len(Var3$) Then
             Var1=Instr(Var3$,"#")
             If Var1 Then
                 VarX=Val(Mid$(Var3$,Var1+1))
                 Var3$=Left$(Var3$,Var1-1)
             Endif
          Endif
          VarZ=0
          For Temp!=Var1! To Var2!
             Call Read.Record(RoomFile,Temp!)
             TempX=False
             If Len(Var3$) Then
                If Left$(Lcase$(Rtrim$(RoomRecord.Custom1)),Len(Var3$))=Lcase$(Var3$) Or _
                   Left$(Lcase$(Rtrim$(RoomRecord.Custom2)),Len(Var3$))=Lcase$(Var3$) Then
                   VarZ=VarZ+1
                   If VarX=0 Or VarZ=VarX Then
                      TempX=True
                   Endif
                Endif
             Endif
             If Var3! Then
                If RoomRecord.Direct(13)=Var3! Then
                   TempX=True
                Endif
             Endif
             If Var3! Then
                If RoomRecord.Direct(14)=Var3! Then
                   TempX=True
                Endif
             Endif
             For Temp4=1 To MaxDirections
                If Var3! Then
                   If RoomRecord.Direct(Temp4)=Var3! Then
                      TempX=True
                      Exit For
                   Endif
                Endif
                If Var4! Then
                   If RoomRecord.Direct(Temp4)=Var4! Then
                      Call Link.Back
                      If Temp8 Then
                         Var2!=RoomRecord.Direct(Temp4)
                         If Var2! Then
                            Call Read.Record(RoomFile,Var2!)
                            If RoomRecord.Direct(Temp8)=Temp! Then
                               TempX=True
                            Endif
                            Call Read.Record(RoomFile,Temp!)
                            If TempX Then
                               Exit For
                            Endif
                         Endif
                      Endif
                   Endif
                Endif
             Next
             If TempX Then
                VarZ1=-1
                For VarQ=1 To 5
                   Call Display.Link(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 Do
                   Endif
                Endif
             Endif
          Next
          Allow.Break=False
          Break=False
          If VarZ1=0 Then
             Strng="No links found."
             Call IO.O
          Endif
          If Continuous Then
             Call More.Prompt
          Endif
          Exit Do
       Case "Q"
          Exit Sub
       End Select
    Loop
 Loop
ErrExit62:
 Exit Sub
ErrResume62:
 Resume ErrExit62
End Sub

Sub Find.Custom2(VarQ,Var3$)
 On Local Error Goto Err.Trp19a
 Line1=0
 Temp1=0
 VarQ=0
 Var4$=Var3$
 Var=Instr(Var4$,"#")
 If Var Then
    Var1=Val(Mid$(Var4$,Var+1))
    Var4$=Left$(Var4$,Var-1)
 Endif
 VarX=0
 Filename=DND.Path+"custom.dat"
 If Dir$(Filename)<>"" Then
    Close #TempFile1
    Open Filename For Input Shared As #TempFile1
    Do While Lost.Carrier=False
       If Eof(TempFile1) Then
          Exit Do
       Endif
       Line1=Line1+1
       Input #TempFile1,Var1$,Var1!,Var2!,X,Y
       Var1$=Ucase$(Left$(Var1$,12))
       If Len(Var1$) Then
          If Left$(Var1$,Len(Var4$))=Ucase$(Var4$) Then
             VarX=VarX+1
             If Var1=0 Or VarX=Var1 Then
                VarQ=-1
                Strng="Custom direction found in datafile in line"+Str$(Line1)+"."
                Graphics.Off=True
                Call IO.O
                Strng=" Room"+Str$(Var1!)+" link to"+Str$(Var2!)
                If X Then
                   Strng=Strng+" (inv)"
                Endif
                If Y Then
                   Strng=Strng+" [level"+Str$(Y)+"]"
                Endif
                Call IO.O
                Temp1 = Temp1 + 2
                If Temp1>=User.Pagelength-2 Then
                   Temp1 = False
                   Call More.Prompt
                   If No Or Quit Then
                      Exit Do
                   Endif
                Endif
             Endif
          Endif
       Endif
    Loop
    If Temp1 Then
       Call More.Prompt
    Endif
 Endif
Err.Rsm19a:
 Exit Sub
Err.Trp19a:
 If Debug.Mode Then
    Strng="Error in " + Ucase$(Filename) + " in line"+Str$(Line1)+"."
    Call IO.O
 Endif
 Resume Err.Rsm19a
End Sub

Sub Link.Back
 Temp8=0
 Select Case Temp4
 Case 1
    Temp8=3
 Case 2
    Temp8=4
 Case 3
    Temp8=1
 Case 4
    Temp8=2
 Case 5
    Temp8=7
 Case 6
    Temp8=8
 Case 7
    Temp8=5
 Case 8
    Temp8=6
 Case 9
    Temp8=10
 Case 10
    Temp8=9
 Case 11
    Temp8=12
 Case 12
    Temp8=11
 End Select
End Sub

Rem 1=north 2=east 3=south 4=west

Square.Data:
 ' east-north-west-south
 Data 2,1,4,3
 ' west-north-east-south
 Data 4,1,2,3
 ' east-south-west-north
 Data 2,3,4,1
 ' west-south-east-north
 Data 4,3,2,1
 ' north-east-south-west
 Data 1,2,3,4
 ' south-east-north-west
 Data 3,2,1,4
 ' north-west-south-east
 Data 1,4,3,2
 ' south-west-north-east
 Data 3,4,1,2

Rem 5=northeast 6=southeast 7=southwest 8=northwest

Diamond.Data:
 ' northeast-southeast-southwest-northwest
 Data 5,6,7,8
 ' northeast-northwest-southwest-southeast
 Data 5,8,7,6
 ' northwest-northeast-southeast-southwest
 Data 8,5,6,7
 ' northwest-southwest-southeast-northeast
 Data 8,7,6,5
 ' southeast-southwest-northwest-northeast
 Data 6,7,8,5
 ' southeast-northeast-northwest-southwest
 Data 6,5,8,7
 ' southwest-northwest-northeast-southeast
 Data 7,8,5,6
 ' southwest-southeast-northeast-northwest
 Data 7,6,5,8
