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

Sub Edit.Room
 On Local Error Goto ErrResume13
 Call Edit.Status.Line
 If Lof(RoomFile)=False Then
    Call Add.Room
 Endif
 Do While Lost.Carrier=False
    If TempC=False Then
       Graphics.Off=False
       Strng="Room Edit Utility Menu:"
       Call IO.O
       Graphics.Off=True
       Strng=RT$(344,"[A]")+"dd"
       Call IO.O
       Strng=RT$(345,"[C]")+"hange"
       Call IO.O
       Strng=RT$(346,"[L]")+"ist"
       Call IO.O
       Strng=RT$(347,"[P]")+"ack"
       Call IO.O
       Strng=RT$(348,"[R]")+"epair"
       Call IO.O
       Strng=RT$(349,"[S]")+"earch"
       Call IO.O
       If Local.Mode Then
          Strng=RT$(590,"[V]")+"Print"
          Call IO.O
       Endif
       Graphics.Off=False
    Endif
    Strng="Room edit option(q to quit)? "
    Line.Length=TempD
    No.Input.Out="Q"
    Call IO.I
    Select Case Ucase$(Out2)
    Case "A"
       If RT$(344,"[A]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Add.Room
          Temp!=Lof(RoomFile)/RoomRecLen
          Call Change.Room
       Endif
    Case "C"
       If RT$(345,"[C]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Find.Room
          If Temp! Then
             Call Change.Room
          Endif
       Endif
    Case "L"
       If RT$(346,"[L]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call List.Room
       Endif
    Case "P"
       If RT$(347,"[P]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Pack.Rooms
       Endif
    Case "R"
       If RT$(348,"[R]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Repair.Rooms(True)
       Endif
    Case "S"
       If RT$(349,"[S]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Search.Room
       Endif
    Case "V"
       If Local.Mode Then
          If RT$(590,"[V]")="[*]" Then
             Strng="Command restricted.."
             Call IO.O
          Else
             Call Print.Rooms
          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
ErrExit13:
 Exit Sub
ErrResume13:
 Resume ErrExit13
End Sub

Sub Add.Room
 On Local Error Goto ErrResume14
 Temp!=Lof(RoomFile)/RoomRecLen+1!
 RoomRecord.Action=SFalse
 RoomRecord.Custom1=Nul
 RoomRecord.Custom2=Nul
 For Var2=1 To MaxDirections
    RoomRecord.Direct(Var2)=SFalse
 Next
 RoomRecord.Direct(13)=SFalse
 RoomRecord.Direct(14)=SFalse
 For Var2=1 To 19
    RoomRecord.LongDesc(Var2)=SFalse
 Next
 RoomRecord.MonClass=SFalse
 RoomRecord.ShortDesc=Nul
 RoomRecord.First=SFalse
 RoomRecord.Last=SFalse
 RoomRecord.First2=SFalse
 RoomRecord.Last2=SFalse
 Call Write.Record(RoomFile,Temp!)
 If User.Index Then
    UserRecord.ObjectsCreated(7)=UserRecord.ObjectsCreated(7)+1#
    Var$=Lcase$(Rtrim$(UserRecord.CodeName))
    Mid$(Var$,1,1)=Ucase$(Mid$(Var$,1,1))
    Call Write.Record(UserFile,User.Index)
 Else
    Var$="<local>"
 Endif
 Close #TempFile1
 Filename$=DND.Path+"created.dat"
 Open Filename$ For Append Shared As #TempFile1
 Var$=Var$+" created room"+Str$(Temp!)+" on "
 Var$=Var$+Format$(Now,"mm-dd-yyyy")+" "+Format$(Now,"hh:mm:ss")
 Print #TempFile1, Var$
 Close #TempFile1
ErrExit14:
 Exit Sub
ErrResume14:
 Resume ErrExit14
End Sub

Sub Find.Room
 On Local Error Goto ErrResume15
 Var1!=Lof(RoomFile)/RoomRecLen
 Strng="Room number"
 Call Get.Record.Range2(1!,Var1!,Temp!)
ErrExit15:
 Exit Sub
ErrResume15:
 Resume ErrExit15
End Sub

Sub Change.Room
 On Local Error Goto ErrResume15a
 Call Read.Record(RoomFile,Temp!)
 Do While Lost.Carrier=False
    Call Write.Record(RoomFile,Temp!)
    Graphics.Off=False
    For VarQ=1 To 3
       Call Display.Room(VarQ)
    Next
    For VarQ=8 To 10
       Call Display.Room(VarQ)
    Next
    Call More.Prompt
    Graphics.Off=True
    If TempC=False Then
       Strng=RT$(350,"[A]")+"ction"
       Call IO.O
       Strng=RT$(351,"[C]")+"ontainers"
       Call IO.O
       Strng=RT$(352,"[D]")+"escription"
       Call IO.O
       Strng=RT$(353,"[M]")+"onster class"
       Call IO.O
       Strng=RT$(354,"[O]")+"bject edit"
       Call IO.O
       Strng=RT$(355,"[T]")+"reasure edit"
       Call IO.O
       Graphics.Off=False
    Endif
    Strng="Room edit option(q to quit)? "
    Line.Length=TempD
    No.Input.Out="Q"
    Call IO.I
    Select Case Ucase$(Out2)
    Case "A"
       If RT$(350,"[A]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Edit.Room.Action
       Endif
    Case "C"
       If RT$(351,"[C]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Edit.Room.Containers
       Endif
    Case "D"
       If RT$(352,"[D]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Edit.Description
       Endif
    Case "M"
       If RT$(353,"[M]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Edit.Room.MonsterClass
       Endif
    Case "O"
       If RT$(354,"[O]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Edit.Room.Objects
       Endif
    Case "T"
       If RT$(355,"[T]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Edit.Room.Treasure
       Endif
    Case "Q"
       Exit Do
    End Select
 Loop
 Call Write.Record(RoomFile,Temp!)
 Strng="Room number"+Str$(Temp!)+" changed."
 Call IO.O
 If User.Index Then
    UserRecord.ObjectsCreated(7)=UserRecord.ObjectsCreated(7)+1#
    Var$=Lcase$(Rtrim$(UserRecord.CodeName))
    Mid$(Var$,1,1)=Ucase$(Mid$(Var$,1,1))
    Call Write.Record(UserFile,User.Index)
 Else
    Var$="<local>"
 Endif
 Close #TempFile1
 Filename$=DND.Path+"created.dat"
 Open Filename$ For Append Shared As #TempFile1
 Var$=Var$+" edited room"+Str$(Temp!)+" on "
 Var$=Var$+Format$(Now,"mm-dd-yyyy")+" "+Format$(Now,"hh:mm:ss")
 Print #TempFile1, Var$
 Close #TempFile1
ErrExit15a:
 Exit Sub
ErrResume15a:
 Resume ErrExit15a
End Sub

Sub Edit.Room.Objects
 On Local Error Goto ErrResume15b
 Do While Lost.Carrier=False
    Graphics.Off=True
    If TempC=False Then
       Strng=RT$(362,"[A]")+"dd"
       Call IO.O
       Strng=RT$(363,"[D]")+"elete"
       Call IO.O
       Strng=RT$(364,"[L]")+"ist"
       Call IO.O
       Graphics.Off=False
    Endif
    Strng="Room object edit option(q to quit)? "
    Line.Length=TempD
    No.Input.Out="Q"
    Call IO.I
    Select Case Ucase$(Out2)
    Case "A"
       If RT$(362,"[A]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          VarQ=False
          Call Find.Object
          If TempD! Then
             Temp2!=Lof(RoomInvFile)/MessWorkRecLen6+1!
             MessWorkRecord6.Room=Temp!
             MessWorkRecord6.User=SFalse
             MessWorkRecord6.Index=-TempD!
             MessWorkRecord6.Charges=False
             MessWorkRecord6.Plus=False
             Call Add.List.Node(Temp2!,Temp!)
             VarQ=True
          Endif
          If VarQ=True Then
             Strng="Object added to room."
          Else
             Strng="Object not added to room."
          Endif
          Call IO.O
       Endif
    Case "D"
       If RT$(363,"[D]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Strng="Object number to delete? "
          No.Input.Out="1"
          Call IO.I
          VarQ=False
          Temp2!=Int(Val(Out2))
          TempX!=SFalse
          If Temp2!>SFalse And Temp2!<=Lof(RoomInvFile)/MessWorkRecLen6 Then
             Var4!=RoomRecord.First
             If Var4! Then
                Do While Lost.Carrier=False
                   Call Read.Record(RoomInvFile,Var4!)
                   Var5!=MessWorkRecord6.Next
                   If MessWorkRecord6.Index<SFalse Then
                      TempX!=TempX!+1!
                      If TempX!=Temp2! Then
                         Call Delete.List.Node(Var4!)
                         Call Clear.List.Node
                         Call Write.Record(RoomInvFile,Var4!)
                         VarQ=True
                         Exit Do
                      Endif
                   Endif
                   If Var5!=SFalse Then
                      Exit Do
                   Endif
                   Var4!=Var5!
                Loop
             Endif
          Endif
          If VarQ=True Then
             Strng="Object deleted from room."
          Else
             Strng="Object not deleted from room."
          Endif
          Call IO.O
       Endif
    Case "L"
       If RT$(364,"[L]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Allow.Break=True
          Break=False
          Continuous=False
          Graphics.Off=True
          Temp8=False
          Temp4!=RoomRecord.First
          TempX!=SFalse
          If Temp4! Then
             Do While Lost.Carrier=False
                Call Read.Record(RoomInvFile,Temp4!)
                If MessWorkRecord6.Room=SFalse Then
                   Exit Do
                Endif
                Temp6!=MessWorkRecord6.Next
                Temp2!=MessWorkRecord6.Index
                If Temp2!<SFalse Then
                   Temp2!=Abs(Temp2!)
                   If Temp2!>SFalse And Temp2!<=Lof(ObjectFile)/ObjectRecLen Then
                      Call Read.Record(ObjectFile,Temp2!)
                      Out3=Rtrim$(ObjectRecord.ObjectName)
                      TempX!=TempX!+1!
                      Strng=Mid$(Str$(TempX!),2)+"."+Out3
                      Call IO.O
                      If Break Then
                         Exit Do
                      Endif
                      Temp8=Temp8+1
                      If Temp8>=User.Pagelength-2 Then
                         Temp8=False
                         If Continuous=False Then
                            Call More.Prompt
                            If No Or Quit Then
                               Exit Do
                            Endif
                         Endif
                      Endif
                   Endif
                Endif
                If Temp6!=SFalse Then
                   Exit Do
                Endif
                Temp4!=Temp6!
             Loop
          Endif
          Allow.Break=False
          Break=False
          If Temp8 Then
             Call More.Prompt
          Endif
       Endif
    Case "Q"
       Exit Do
    End Select
 Loop
ErrExit15b:
 Exit Sub
ErrResume15b:
 Resume ErrExit15b
End Sub

Sub Edit.Room.Treasure
 On Local Error Goto ErrResume15c
 Do While Lost.Carrier=False
    Graphics.Off=True
    If TempC=False Then
       Strng=RT$(365,"[A]")+"dd"
       Call IO.O
       Strng=RT$(366,"[D]")+"elete"
       Call IO.O
       Strng=RT$(367,"[L]")+"ist
       Call IO.O
       Graphics.Off=False
    Endif
    Strng="Room treasure edit option(q to quit)? "
    Line.Length=TempD
    No.Input.Out="Q"
    Call IO.I
    Select Case Ucase$(Out2)
    Case "A"
       If RT$(365,"[A]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          VarQ=False
          Call Find.Treasure
          If TempC! Then
             If TreasureRecord.Container=False Then
                Temp2!=Lof(RoomInvFile)/MessWorkRecLen6+1!
                MessWorkRecord6.Room=Temp!
                MessWorkRecord6.User=SFalse
                MessWorkRecord6.Index=TempC!
                MessWorkRecord6.Charges=TreasureRecord.Charges
                MessWorkRecord6.Plus=False
                Call Add.List.Node(Temp2!,Temp!)
                VarQ=True
             Endif
          Endif
          If VarQ=True Then
             Strng="Treasure added to room."
          Else
             Strng="Treasure not added to room."
          Endif
          Call IO.O
       Endif
    Case "D"
       If RT$(366,"[D]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Strng="Treasure number to delete? "
          No.Input.Out="1"
          Call IO.I
          VarQ=False
          Temp2!=Int(Val(Out2))
          TempX!=SFalse
          If Temp2!>SFalse And Temp2!<=Lof(RoomInvFile)/MessWorkRecLen6 Then
             Var4!=RoomRecord.First
             If Var4! Then
                Do While Lost.Carrier=False
                   Call Read.Record(RoomInvFile,Var4!)
                   Var5!=MessWorkRecord6.Next
                   If MessWorkRecord6.Index>SFalse Then
                      TempX!=TempX!+1!
                      If TempX!=Temp2! Then
                         Call Delete.List.Node(Var4!)
                         Call Clear.List.Node
                         Call Write.Record(RoomInvFile,Var4!)
                         VarQ=True
                         Exit Do
                      Endif
                   Endif
                   If Var5!=SFalse Then
                      Exit Do
                   Endif
                   Var4!=Var5!
                Loop
             Endif
          Endif
          If VarQ=True Then
             Strng="Treasure deleted from room."
          Else
             Strng="Treasure not deleted from room."
          Endif
          Call IO.O
       Endif
    Case "L"
       If RT$(367,"[L]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Allow.Break=True
          Break=False
          Continuous=False
          Graphics.Off=True
          Temp8=False
          Temp4!=RoomRecord.First
          TempX!=SFalse
          If Temp4! Then
             Do While Lost.Carrier=False
                Call Read.Record(RoomInvFile,Temp4!)
                If MessWorkRecord6.Room=SFalse Then
                   Exit Do
                Endif
                Temp6!=MessWorkRecord6.Next
                Temp2!=MessWorkRecord6.Index
                If Temp2!>SFalse And Temp2!<=Lof(TreasureFile)/TreasureRecLen Then
                   Call Read.Record(TreasureFile,Temp2!)
                   TempX!=TempX!+1!
                   Out3=Rtrim$(TreasureRecord.TreasureName)
                   Strng=Mid$(Str$(TempX!),2)+"."+Out3
                   If TreasureRecord.Plus Then
                      Strng=Strng+"(+"+Mid$(Str$(TreasureRecord.Plus),2)+")"
                   Endif
                   If MessWorkRecord6.Charges Then
                      Strng=Strng+"(charges:"+Str$(MessWorkRecord6.Charges)+")"
                   Endif
                   Call IO.O
                   If Break Then
                      Exit Do
                   Endif
                   Temp8=Temp8+1
                   If Temp8>=User.Pagelength-2 Then
                      Temp8=False
                      If Continuous=False Then
                         Call More.Prompt
                         If No Or Quit Then
                            Exit Do
                         Endif
                      Endif
                   Endif
                Endif
                If Temp6!=SFalse Then
                   Exit Do
                Endif
                Temp4!=Temp6!
             Loop
          Endif
          Allow.Break=False
          Break=False
          If Temp8 Then
             Call More.Prompt
          Endif
       Endif
    Case "Q"
       Exit Do
    End Select
 Loop
ErrExit15c:
 Exit Sub
ErrResume15c:
 Resume ErrExit15c
End Sub

Sub Edit.Description
 On Local Error Goto ErrResume16
 Do While Lost.Carrier=False
    Graphics.Off=False
    Strng="Room description edit options:"
    Call IO.O
    If TempC=False Then
       Graphics.Off=True
       Strng=RT$(359,"[D]")+"isplay description"
       Call IO.O
       Strng=RT$(360,"[L]")+"ong description"
       Call IO.O
       Strng=RT$(361,"[S]")+"hort description"
       Call IO.O
    Endif
    Graphics.Off=False
    Strng="Room description edit option(q to quit)? "
    Line.Length=TempD
    No.Input.Out="Q"
    Call IO.I
    Select Case Ucase$(Out2)
    Case "D"
       If RT$(359,"[D]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
       Graphics.Off=False
       Strng="Current short description:"
       Call IO.O
       Graphics.Off=True
       Strng=RoomRecord.ShortDesc
       Var=Instr(Strng,Chr$(0))
       If Var Then
          Strng=Left$(Strng,Var-1)
       Endif
       Strng=Rtrim$(Strng)
       If Strng=Nul Then
          Strng="<none>"
       Endif
       Call IO.O
       Call More.Prompt
       Graphics.Off=False
       Strng="Current long description:"
       Call IO.O
       TempZ=False
       Graphics.Off=True
       For TempQ=19 To 1 Step -1
          If RoomRecord.LongDesc(TempQ)>SFalse Then
             Exit For
          Endif
       Next
       For TempY=1 To TempQ
          TempR!=RoomRecord.LongDesc(TempY)
          If TempR!>SFalse And TempR!<=Lof(RoomDescFile)/RoomDescLen Then
             Call Read.Record(RoomDescFile,TempR!)
             Strng=BufferRecord.Buffer
             Strng=Rtrim$(Strng)
             TempZ=True
             Call IO.O
          Endif
       Next
       If TempZ=False Then
          Strng="<none>"
          Call IO.O
       Endif
       Call More.Prompt
       Endif
    Case "L"
       If RT$(360,"[L]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
       No.Input.Out=Nul
       Line.Length=TempD
       Graphics.Off=False
       Strng="Edit long description(y/n)? "
       Call IO.I
       If Yes Then
          Redim Temp.ArrayS(1 To 19) As String
          For TempY=1 To 19
             Temp.ArrayS(TempY)=Nul
          Next
          Message.Length=False
          For TempY=1 To 19
             TempQ!=RoomRecord.LongDesc(TempY)
             If TempQ!>SFalse And TempQ!<=Lof(RoomDescFile)/RoomDescLen Then
                Call Read.Record(RoomDescFile,TempQ!)
                Strng=BufferRecord.Buffer
                Strng=Rtrim$(Strng)
                Message.Length=TempY
                Temp.ArrayS(TempY)=Strng
             Endif
          Next
          Do While Lost.Carrier=False
             Call Edit.Message(VarX)
             Select Case VarX
             Case -1
                If Message.Length=19 Then
                   Strng="Description buffer full."
                   Call IO.O
                Else
                   Strng="Continue editing. Press "+Enter$+" on a blank line to edit."
                   Call IO.O
                   Do While Lost.Carrier=False
                      Graphics.Off=True
                      If Message.Length<19 Then
                         Word.Wrap=True
                      Else
                         Word.Wrap=False
                      Endif
                      Strng="?"
                      Carriage.Return=-1
                      Call IO.O
                      Call IO.I
                      If No.Input Then
                         Exit Do
                      Endif
                      Message.Length=Message.Length+1
                      Temp.ArrayS(Message.Length)=Out2
                      If Message.Length=19 Then
                         Strng="Description buffer full."
                         Call IO.O
                         Exit Do
                      Endif
                   Loop
                Endif
             Case 0
                Exit Do
             Case 1
                Call Store.Description
                Exit Do
             End Select
          Loop
       Endif
       Endif
    Case "S"
       If RT$(361,"[S]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
       Graphics.Off=False
       Strng="Enter short description(80 characters):"
       Call IO.O
       Graphics.Off=True
       Strng="Press "+Enter$+" to leave unchanged."
       Call IO.O
       Line.Length=80
       Strng="?"
       Call IO.I
       If No.Input=False Then
          RoomRecord.ShortDesc=Out2
       Endif
       Endif
    Case "Q"
       Exit Do
    End Select
 Loop
ErrExit16:
 Exit Sub
ErrResume16:
 Resume ErrExit16
End Sub

Sub Store.Description
 On Local Error Goto ErrResume16a
 For TempZ=1 To Message.Length
    TempQ!=RoomRecord.LongDesc(TempZ)
    If TempQ!>SFalse And TempQ!<=Lof(RoomDescFile)/RoomDescLen Then
       Call Read.Record(RoomDescFile,TempQ!)
       BufferRecord.Buffer=Temp.ArrayS(TempZ)
       Call Write.Record(RoomDescFile,TempQ!)
    Else
       TempQ!=Lof(RoomDescFile)/RoomDescLen+1!
       RoomRecord.LongDesc(TempZ)=TempQ!
       BufferRecord.Buffer=Temp.ArrayS(TempZ)
       Call Write.Record(RoomDescFile,TempQ!)
    Endif
 Next
ErrExit16a:
 Exit Sub
ErrResume16a:
 Resume ErrExit16a
End Sub

Sub Edit.Room.MonsterClass
 On Local Error Goto ErrResume17
 Temp3!=Lof(MonClassFile)/MonClassRecLen
 Strng="Monster class"
 Call Get.Record.Range2(SFalse,Temp3!,Temp2!)
 RoomRecord.MonClass=Temp2!
ErrExit17:
 Exit Sub
ErrResume17:
 Resume ErrExit17
End Sub

Sub Edit.Room.Action
 On Local Error Goto ErrResume18
 Temp3!=Lof(ActionFile)/ActionRecLen
 Strng="Action number"
 Call Get.Record.Range2(SFalse,Temp3!,Temp2!)
 RoomRecord.Action=Temp2!
ErrExit18:
 Exit Sub
ErrResume18:
 Resume ErrExit18
End Sub

Sub Edit.Room.Containers
 On Local Error Goto ErrResume18a
 Do While Lost.Carrier=False
    Graphics.Off=True
    If TempC=False Then
       Strng=RT$(356,"[A]")+"dd"
       Call IO.O
       Strng=RT$(357,"[D]")+"elete"
       Call IO.O
       Strng=RT$(358,"[L]")+"ist"
       Call IO.O
       Graphics.Off=False
    Endif
    Strng="Room container edit option(q to quit)? "
    Line.Length=TempD
    No.Input.Out="Q"
    Call IO.I
    Select Case Ucase$(Out2)
    Case "A"
       If RT$(356,"[A]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          VarQ=False
          Call Find.Treasure
          If TempC! Then
             If TreasureRecord.Container Then
                Call Add.Container.To.Room
                VarQ=True
             Endif
          Endif
          If VarQ=True Then
             Strng="Container added to room."
          Else
             Strng="Container not added to room."
          Endif
          Call IO.O
       Endif
    Case "D"
       If RT$(357,"[A]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Strng="Number to delete? "
          No.Input.Out="0"
          Call IO.I
          VarQ=False
          Temp2!=Int(Val(Out2))
          TempX!=SFalse
          If Temp2!>=SFalse And Temp2!<=Lof(ContainerFile)/ContainerRecLen Then
             Var4!=RoomRecord.First2
             If Var4! Then
                Do While Lost.Carrier=False
                   Call Read.Record(ContainerFile,Var4!)
                   Var5!=ContainerRecord.Next
                   If ContainerRecord.WithinContainer=SFalse Then
                      If ContainerRecord.DeletedContainer=False Then
                         TempX!=TempX!+1!
                         If TempX!=Temp2! Then
                            Call Delete.Room.Container(Var4!,Temp!)
                            Call Clear.Container.Node
                            Call Write.Record(ContainerFile,Var4!)
                            VarQ=True
                            Exit Do
                         Endif
                      Endif
                   Endif
                   If Var5!=SFalse Then
                      Exit Do
                   Endif
                   Var4!=Var5!
                Loop
             Endif
          Endif
          If VarQ=True Then
             Strng="Container deleted from room."
          Else
             Strng="Container not deleted from room."
          Endif
          Call IO.O
       Endif
    Case "L"
       If RT$(358,"[L]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Graphics.Off=True
          VarZ=False
          Allow.Break=True
          Break=False
          Continuous=False
          Temp5!=RoomRecord.First2
          TempX!=SFalse
          If Temp5! Then
             Do While Lost.Carrier=False
                Call Read.Record(ContainerFile,Temp5!)
                Var6!=ContainerRecord.Next
                If ContainerRecord.WithinContainer=SFalse Then
                   If ContainerRecord.DeletedContainer=False Then
                      Out3=ContainerRecord.ContainerName
                      Out3=Rtrim$(Out3)
                      Out3=Lcase$(Out3)
                      TempX!=TempX!+1!
                      Strng=Mid$(Str$(TempX!),2)+"."+Out3
                      If ContainerRecord.InvisibleContainer Then
                         Strng=Strng+"[inv]"
                      Endif
                      Call IO.O
                      If Break Then
                         Exit Do
                      Endif
                      VarZ=VarZ+1
                      If VarZ>=User.Pagelength-2 Then
                         VarZ=False
                         If Continuous=False Then
                            Call More.Prompt
                            If No Or Quit Then
                               Exit Do
                            Endif
                         Endif
                      Endif
                   Endif
                Endif
                If Var6!=SFalse Then
                   Exit Do
                Endif
                Temp5!=Var6!
             Loop
          Endif
          Allow.Break=False
          If VarZ Then
             Call More.Prompt
          Endif
       Endif
    Case "Q"
       Exit Do
    End Select
 Loop
ErrExit18a:
 Exit Sub
ErrResume18a:
 Resume ErrExit18a
End Sub

Sub List.Room
 On Local Error Goto ErrResume19
 Var!=Lof(RoomFile)/RoomRecLen
 Call Get.Record.Range(Var1!,Var2!,Var!)
 Allow.Break=True
 Break=False
 Continuous=False
 For Temp!=Var1! To Var2!
    Call Read.Record(RoomFile,Temp!)
    For VarQ=1 To 10
       Call Display.Room(VarQ)
       If No Or Quit Then
	  Exit For
       Endif
       If Break Then
	  Exit For
       Endif
    Next
    If Break Then
       Exit For
    Endif
    If No Or Quit 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
ErrExit19:
 Exit Sub
ErrResume19:
 Resume ErrExit19
End Sub

Sub Print.Rooms
 On Local Error Goto ErrResume19a
 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
    Var!=Lof(RoomFile)/RoomRecLen
    Call Get.Record.Range(Var1!,Var2!,Var!)
    For Temp!=Var1! To Var2!
       Call Read.Record(RoomFile,Temp!)
       For VarQ=1 To 10
          Call Print.Room(VarQ)
       Next
       Print #TempFile1,Chr$(12);
    Next
 Endif
ErrExit19a:
 Close #TempFile1
 Exit Sub
ErrResume19a:
 Resume ErrExit19a
End Sub

Sub Display.Room(VarZ)
 On Local Error Goto ErrResume20
 Graphics.Off=True
 Select Case VarZ
 Case 1
 Strng="Room number"+Str$(Temp!)+":"
 Call IO.O
 Case 2
 Strng="Monster class:"+Str$(RoomRecord.MonClass)+"."
 Call IO.O
 Case 3
 Strng="Action number:"+Str$(RoomRecord.Action)+"."
 Call IO.O
 Case 4
 Graphics.Off=False
 Strng="Short description:"
 Call IO.O
 Case 5
 Graphics.Off=True
 Strng=RoomRecord.ShortDesc
 Var=Instr(Strng,Chr$(0))
 If Var Then
    Strng=Left$(Strng,Var-1)
 Endif
 Strng=Rtrim$(Strng)
 If Strng=Nul Then
    Strng="<none>"
 Endif
 Call IO.O
 If Continuous=False Then
    Call More.Prompt
 Endif
 Case 6
 Graphics.Off=False
 Strng="Long description:"
 Call IO.O
 Case 7
    Graphics.Off=True
    TempW=False
    For TempP=19 To 1 Step -1
       If RoomRecord.LongDesc(TempP)>SFalse Then
          Exit For
       Endif
    Next
    For TempY=1 To TempP
       TempQ!=RoomRecord.LongDesc(TempY)
       If TempQ!>SFalse And TempQ!<=Lof(RoomDescFile)/RoomDescLen Then
          Call Read.Record(RoomDescFile,TempQ!)
          Strng=BufferRecord.Buffer
          Strng=Rtrim$(Strng)
          If Strng<>Nul Then
             TempW=True
             Call IO.O
             If Break Then
                Exit For
             Endif
          Endif
       Endif
    Next
    If TempW=False Then
       If Break=False Then
          Strng="<none>"
          Call IO.O
       Endif
    Endif
    If Continuous=False Then
       Call More.Prompt
    Endif
 Case 8
    Var3!=SFalse
    Var2!=RoomRecord.First
    If Var2! Then
       Do While Lost.Carrier=False
          Call Read.Record(RoomInvFile,Var2!)
          If MessWorkRecord6.Room=SFalse Then
             Exit Do
          Endif
          Var6!=MessWorkRecord6.Next
          VarX!=MessWorkRecord6.Index
          If VarX!<SFalse Then
             VarX!=Abs(VarX!)
             If VarX!>SFalse And VarX!<=Lof(ObjectFile)/ObjectRecLen Then
                Var3!=Var3!+1!
             Endif
          Endif
          If Var6!=SFalse Then
             Exit Do
          Endif
          Var2!=Var6!
       Loop
    Endif
    Strng="Objects:"+Str$(Var3!)+"."
    Call IO.O
 Case 9
    Var3!=SFalse
    Var2!=RoomRecord.First
    If Var2! Then
       Do While Lost.Carrier=False
          Call Read.Record(RoomInvFile,Var2!)
          If MessWorkRecord6.Room=SFalse Then
             Exit Do
          Endif
          Var6!=MessWorkRecord6.Next
          VarX!=MessWorkRecord6.Index
          If VarX!>SFalse Then
             If VarX!>SFalse And VarX!<=Lof(TreasureFile)/TreasureRecLen Then
                Var3!=Var3!+1!
             Endif
          Endif
          If Var6!=SFalse Then
             Exit Do
          Endif
          Var2!=Var6!
       Loop
    Endif
    Strng="Treasure:"+Str$(Var3!)+"."
    Call IO.O
 Case 10
    Var3!=SFalse
    Var5!=RoomRecord.First2
    If Var5! Then
       Do While Lost.Carrier=False
          Call Read.Record(ContainerFile,Var5!)
          Var6!=ContainerRecord.Next
          If ContainerRecord.WithinContainer=SFalse Then
             If ContainerRecord.DeletedContainer=False Then
                Var3!=Var3!+1!
             Endif
          Endif
          If Var6!=SFalse Then
             Exit Do
          Endif
          Var5!=Var6!
       Loop
    Endif
    Strng="Containers:"+Str$(Var3!)+"."
    Call IO.O
 End Select
 Graphics.Off=False
ErrExit20:
 Exit Sub
ErrResume20:
 Resume ErrExit20
End Sub

Sub Print.Room(VarZ)
 On Local Error Goto ErrResume20a
 Graphics.Off=True
 Select Case VarZ
 Case 1
 Strng="Room number"+Str$(Temp!)+":"
 Print #TempFile1,Strng
 Case 2
 Strng="Monster class:"+Str$(RoomRecord.MonClass)+"."
 Print #TempFile1,Strng
 Case 3
 Strng="Action number:"+Str$(RoomRecord.Action)+"."
 Print #TempFile1,Strng
 Case 4
 Graphics.Off=False
 Strng="Short description:"
 Print #TempFile1,Strng
 Case 5
 Graphics.Off=True
 Strng=RoomRecord.ShortDesc
 Var=Instr(Strng,Chr$(0))
 If Var Then
    Strng=Left$(Strng,Var-1)
 Endif
 Strng=Rtrim$(Strng)
 If Strng=Nul Then
    Strng="<none>"
 Endif
 Print #TempFile1,Strng
 Case 6
 Graphics.Off=False
 Strng="Long description:"
 Print #TempFile1,Strng
 Case 7
    TempW=False
    For TempP=19 To 1 Step -1
       If RoomRecord.LongDesc(TempP)>SFalse Then
          Exit For
       Endif
    Next
    For TempY=1 To TempP
       TempQ!=RoomRecord.LongDesc(TempY)
       If TempQ!>SFalse And TempQ!<=Lof(RoomDescFile)/RoomDescLen Then
          Call Read.Record(RoomDescFile,TempQ!)
          Strng=BufferRecord.Buffer
          Strng=Rtrim$(Strng)
          If Strng<>Nul Then
             TempW=True
             Print #TempFile1,Strng
          Endif
       Endif
    Next
    If TempW=False Then
       Strng="<none>"
       Print #TempFile1,Strng
    Endif
 Case 8
    Temp3!=SFalse
    Temp2!=RoomRecord.First
    If Temp2! Then
       Do While Lost.Carrier=False
          Call Read.Record(RoomInvFile,Temp2!)
          If MessWorkRecord6.Room=SFalse Then
             Exit Do
          Endif
          Temp6!=MessWorkRecord6.Next
          VarX!=MessWorkRecord6.Index
          If VarX!<SFalse Then
             VarX!=Abs(VarX!)
             If VarX!>SFalse And VarX!<=Lof(ObjectFile)/ObjectRecLen Then
                Temp3!=Temp3!+1!
             Else
                MessWorkRecord6.Room=SFalse
                Call Write.Record(RoomInvFile,Temp2!)
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
    Strng="Objects:"+Str$(Temp3!)+"."
    Print #TempFile1,Strng
 Case 9
    Temp3!=SFalse
    Temp2!=RoomRecord.First
    If Temp2! Then
       Do While Lost.Carrier=False
          Call Read.Record(RoomInvFile,Temp2!)
          If MessWorkRecord6.Room=SFalse Then
             Exit Do
          Endif
          Temp6!=MessWorkRecord6.Next
          VarX!=MessWorkRecord6.Index
          If VarX!>SFalse Then
             If VarX!>SFalse And VarX!<=Lof(TreasureFile)/TreasureRecLen Then
                Temp3!=Temp3!+1!
             Else
                MessWorkRecord6.Room=SFalse
                Call Write.Record(RoomInvFile,Temp2!)
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
    Strng="Treasure:"+Str$(Temp3!)+"."
    Print #TempFile1,Strng
 Case 10
    Temp3!=SFalse
    Temp5!=RoomRecord.First2
    If Temp5! Then
       Do While Lost.Carrier=False
          Call Read.Record(ContainerFile,Temp5!)
          Var6!=ContainerRecord.Next
          If ContainerRecord.WithinContainer=SFalse Then
             If ContainerRecord.DeletedContainer=False Then
                Temp3!=Temp3!+1!
             Endif
          Endif
          If Var6!=SFalse Then
             Exit Do
          Endif
          Temp5!=Var6!
       Loop
    Endif
    Strng="Containers:"+Str$(Temp3!)+"."
    Print #TempFile1,Strng
 End Select
 Graphics.Off=False
ErrExit20a:
 Exit Sub
ErrResume20a:
 Resume ErrExit20a
End Sub

Sub Search.Room
 On Local Error Goto ErrResume60
 Do While Lost.Carrier=False
    VarS1!=SFalse
    VarS2!=SFalse
    Temp0$=Nul
    Temp1$=Nul
    Temp2$=Nul
    Temp3$=Nul
    Temp4$=Nul
    Do While Lost.Carrier=False
       Graphics.Off=True
       If TempC=False Then
          Strng="[A]ction"
          If VarS1! Then
             Strng=Strng+Space$(30-Len(Strng))
             Strng=Strng+"("+Mid$(Str$(VarS1!),2)+")"
          Endif
          Call IO.O
          Strng="[B]Monclass"
          If VarS2! Then
             Strng=Strng+Space$(30-Len(Strng))
             Strng=Strng+"("+Mid$(Str$(VarS2!),2)+")"
          Endif
          Call IO.O
          Strng="[C]Container"
          If Temp4$<>Nul Then
             Strng=Strng+Space$(30-Len(Strng))
             Strng=Strng+"("+Temp4$+")"
          Endif
          Call IO.O
          Strng="[D]Object"
          If Temp0$<>Nul Then
             Strng=Strng+Space$(30-Len(Strng))
             Strng=Strng+"("+Temp0$+")"
          Endif
          Call IO.O
          Strng="[E]Treasure"
          If Temp1$<>Nul Then
             Strng=Strng+Space$(30-Len(Strng))
             Strng=Strng+"("+Temp1$+")"
          Endif
          Call IO.O
          Strng="[F]Short description"
          If Temp2$<>Nul Then
             Strng=Strng+Space$(30-Len(Strng))
             Strng=Strng+"("+Temp2$+")"
          Endif
          Call IO.O
          Strng="[G]Long description"
          If Temp3$<>Nul Then
             Strng=Strng+Space$(30-Len(Strng))
             Strng=Strng+"("+Temp3$+")"
          Endif
          Call IO.O
          Graphics.Off=False
       Endif
       Strng="Description 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="Action number? "
          Call IO.I
          VarS1!=Int(Val(Out2))
       Case "B"
          Strng="Monclass number? "
          Call IO.I
          VarS2!=Int(Val(Out2))
       Case "C"
          Strng="Container description substring? "
          Call IO.I
          Out2=Lcase$(Out2)
          Temp4$=Out2
       Case "D"
          Strng="Object description substring? "
          Call IO.I
          Out2=Lcase$(Out2)
          Temp0$=Out2
       Case "E"
          Strng="Treasure description substring? "
          Call IO.I
          Out2=Lcase$(Out2)
          Temp1$=Out2
       Case "F"
          Strng="Short description substring? "
          Call IO.I
          Out2=Lcase$(Out2)
          Temp2$=Out2
       Case "G"
          Strng="Long description substring? "
          Call IO.I
          Out2=Lcase$(Out2)
          Temp3$=Out2
       Case "S"
          Var!=Lof(RoomFile)/RoomRecLen
          Call Get.Record.Range(Var1!,Var2!,Var!)
          Allow.Break=True
          Break=False
          Continuous=False
          VarZ1!=0!
          VarZ2!=0!
          If Temp0$<>Nul Then
             VarZ=Instr(Temp0$,"#")
             If VarZ Then
                VarZ2!=Int(Val(Mid$(Temp0$,VarZ+1)))
                Temp0$=Left$(Temp0$,VarZ-1)
             Endif
          Endif
          VarZ8!=0!
          VarZ9!=0!
          If Temp1$<>Nul Then
             VarZ=Instr(Temp1$,"#")
             If VarZ Then
                VarZ9!=Int(Val(Mid$(Temp1$,VarZ+1)))
                Temp1$=Left$(Temp1$,VarZ-1)
             Endif
          Endif
          VarZ10!=0!
          VarZ11!=0!
          If Temp4$<>Nul Then
             VarZ=Instr(Temp4$,"#")
             If VarZ Then
                VarZ11!=Int(Val(Mid$(Temp4$,VarZ+1)))
                Temp4$=Left$(Temp4$,VarZ-1)
             Endif
          Endif
          VarZ12!=0!
          VarZ13!=0!
          If Temp2$<>Nul Then
             VarZ=Instr(Temp2$,"#")
             If VarZ Then
                VarZ13!=Int(Val(Mid$(Temp2$,VarZ+1)))
                Temp2$=Left$(Temp2$,VarZ-1)
             Endif
          Endif
          VarZ14!=0!
          VarZ15!=0!
          If Temp3$<>Nul Then
             VarZ=Instr(Temp3$,"#")
             If VarZ Then
                VarZ15!=Int(Val(Mid$(Temp3$,VarZ+1)))
                Temp3$=Left$(Temp3$,VarZ-1)
             Endif
          Endif
          For Temp!=Var1! To Var2!
             TempX=False
             Call Read.Record(RoomFile,Temp!)
             If VarS1! Then
                If RoomRecord.Action=VarS1! Then
                   TempX=True
                Endif
             Endif
             If VarS2! Then
                If RoomRecord.MonClass=VarS2! Then
                   TempX=True
                Endif
             Endif
             If Temp0$<>Nul Then
                Var3!=RoomRecord.First
                If Var3! Then
                   Do While Lost.Carrier=False
                      Call Read.Record(RoomInvFile,Var3!)
                      If MessWorkRecord6.Room=SFalse Then
                         Exit Do
                      Endif
                      Var6!=MessWorkRecord6.Next
                      VarX!=MessWorkRecord6.Index
                      If VarX!<SFalse Then
                         VarX!=Abs(VarX!)
                         If VarX!>SFalse And VarX!<=Lof(ObjectFile)/ObjectRecLen Then
                            Call Read.Record(ObjectFile,VarX!)
                            Out3=Rtrim$(ObjectRecord.ObjectName)
                            Call InstrSUB(VarX,Out3,Temp0$)
                            If VarX Then
                               VarZ1!=VarZ1!+1!
                               If VarZ2!=0! Or VarZ1!=VarZ2! Then
                                  TempX=True
                               Endif
                            Endif
                         Endif
                      Endif
                      If Var6!=SFalse Then
                         Exit Do
                      Endif
                      Var3!=Var6!
                   Loop
                Endif
             Endif
             If Temp1$<>Nul Then
                Var3!=RoomRecord.First
                If Var3! Then
                   Do While Lost.Carrier=False
                      Call Read.Record(RoomInvFile,Var3!)
                      If MessWorkRecord6.Room=SFalse Then
                         Exit Do
                      Endif
                      Var6!=MessWorkRecord6.Next
                      VarX!=MessWorkRecord6.Index
                      If VarX!>SFalse Then
                         If VarX!>SFalse And VarX!<=Lof(ObjectFile)/ObjectRecLen Then
                            Call Read.Record(TreasureFile,VarX!)
                            Out3=Rtrim$(TreasureRecord.TreasureName)
                            Call InstrSUB(VarX,Out3,Temp1$)
                            If VarX Then
                               VarZ8!=VarZ8!+1!
                               If VarZ9!=0! Or VarZ8!=VarZ9! Then
                                  TempX=True
                               Endif
                            Endif
                         Endif
                      Endif
                      If Var6!=SFalse Then
                         Exit Do
                      Endif
                      Var3!=Var6!
                   Loop
                Endif
             Endif
             If Temp4$<>Nul Then
                Var3!=RoomRecord.First2
                If Var3! Then
                   Do While Lost.Carrier=False
                      Call Read.Record(ContainerFile,Var3!)
                      Var6!=ContainerRecord.Next
                      If ContainerRecord.WithinContainer=SFalse Then
                         If ContainerRecord.DeletedContainer=False Then
                            Out3=Rtrim$(ContainerRecord.ContainerName)
                            Call InstrSUB(VarX,Out3,Temp4$)
                            If VarX Then
                               VarZ10!=VarZ10!+1!
                               If VarZ11!=0! Or VarZ10!=VarZ11! Then
                                  TempX=True
                               Endif
                            Endif
                            If TempX Then
                               Exit Do
                            Endif
                         Endif
                      Endif
                      If Var6!=SFalse Then
                         Exit Do
                      Endif
                      Var3!=Var6!
                   Loop
                Endif
             Endif
             If Temp2$<>Nul Then
                Out3=Rtrim$(RoomRecord.ShortDesc)
                Call InstrSUB(VarX,Out3,Temp2$)
                If VarX Then
                   VarZ12!=VarZ12!+1!
                   If VarZ13!=0! Or VarZ12!=VarZ13! Then
                      TempX=True
                   Endif
                Endif
             Endif
             If Temp3$<>Nul Then
                For Var=1 To 19
                   TempQ!=RoomRecord.LongDesc(Var)
                   If TempQ!>SFalse And TempQ!<=Lof(RoomDescFile)/RoomDescLen Then
                      Call Read.Record(RoomDescFile,TempQ!)
                      Out3=Rtrim$(BufferRecord.Buffer)
                      If Out3<>Nul Then
                         Call InstrSUB(VarX,Out3,Temp3$)
                         If VarX Then
                            VarZ14!=VarZ14!+1!
                            If VarZ15!=0! Or VarZ14!=VarZ15! Then
                               TempX=True
                            Endif
                         Endif
                         If TempX Then
                            Exit For
                         Endif
                      Endif
                   Endif
                Next
             Endif
             If TempX Then
                For VarQ=1 To 3
                   Call Display.Room(VarQ)
                   If No Or Quit Then
                      Exit For
                   Endif
                   If Break Then
                      Exit For
                   Endif
                Next
                If Break Then
                   Exit For
                Endif
                If No Or Quit 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
ErrExit60:
 Exit Sub
ErrResume60:
 Resume ErrExit60
End Sub

Sub Delete.List.Node(VarZ!)
 On Local Error Goto ErrorTrp32a
 Call Read.Record(RoomFile,Temp!)
 If RoomRecord.First=VarZ! Then
    Call Read.Record(RoomInvFile,VarZ!)
    RoomRecord.First=MessWorkRecord6.Next
    Call Write.Record(RoomFile,Temp!)
    If RoomRecord.First>SFalse Then
       Call Read.Record(RoomInvFile,RoomRecord.First)
       MessWorkRecord6.Prev=SFalse
       Call Write.Record(RoomInvFile,RoomRecord.First)
    Endif
 Else
    If RoomRecord.Last=VarZ! Then
       Call Read.Record(RoomInvFile,VarZ!)
       RoomRecord.Last=MessWorkRecord6.Prev
       Call Write.Record(RoomFile,Temp!)
       If RoomRecord.Last>SFalse Then
          Call Read.Record(RoomInvFile,RoomRecord.Last)
          MessWorkRecord6.Next=SFalse
          Call Write.Record(RoomInvFile,RoomRecord.Last)
       Endif
    Else
       Call Read.Record(RoomInvFile,VarZ!)
       Previous.Node!=MessWorkRecord6.Prev
       Next.Node!=MessWorkRecord6.Next
       Call Read.Record(RoomInvFile,Previous.Node!)
       MessWorkRecord6.Next=Next.Node!
       Call Write.Record(RoomInvFile,Previous.Node!)
       Call Read.Record(RoomInvFile,Next.Node!)
       MessWorkRecord6.Prev=Previous.Node!
       Call Write.Record(RoomInvFile,Next.Node!)
    Endif
 Endif
ErrorRsm32a:
 Exit Sub
ErrorTrp32a:
 Resume ErrorRsm32a
End Sub

Sub Pack.Rooms
 On Local Error Goto ErrResume65
 Call Search.Mess2(Var2)
 If Var2 Then
    Strng="Can't pack while node/user online."
    Call IO.O
    Exit Sub
 Endif
 Strng="Pack room inventory file(y/n)? "
 Line.Length=TempD
 No.Input.Out="Y"
 Call IO.I
 If Yes Then
    Call Repair.Rooms(False)
    Carriage.Return=True
    Graphics.Off=True
    Strng="Making backup of room inventory file"
    Call IO.O
    Close #TempFile1
    FileName=Data.Path1+"ROOMINV.BAK"
    If Dir$(FileName)<>Nul Then
       Kill FileName
    Endif
    VarD=False
    VarE=False
    VarF!=Timeit!
    Open FileName For Random Shared As #TempFile1 Len=MessWorkRecLen6
    For Temp5!=1! To Lof(RoomInvFile)/MessWorkRecLen6
       Call Read.Record(RoomInvFile,Temp5!)
       Call Write.TempFile(7,Temp5!)
       Call Dot.Display(VarD,VarE,VarF!)
    Next
    Call IO.O
    Carriage.Return=True
    Strng="Packing room inventory file"
    Call IO.O
    Close #RoomInvFile
    FileName=RoomInv.FileName
    If Dir$(FileName)<>Nul Then
       Kill FileName
    Endif
    Open FileName For Random Shared As #RoomInvFile Len=MessWorkRecLen6
    VarD=False
    VarE=False
    VarF!=Timeit!
    For Temp!=1! To Lof(RoomFile)/RoomRecLen
       Call Read.Record(RoomFile,Temp!)
       Temp5!=RoomRecord.First
       If Temp5! Then
          RoomRecord.First=SFalse
          RoomRecord.Last=SFalse
          Call Write.Record(RoomFile,Temp!)
          Do
             Call Read.TempFile(7,Temp5!)
             Temp6!=MessWorkRecord6.Next
             Temp7!=Lof(RoomInvFile)/MessWorkRecLen6+1!
             Call Add.List.Node(Temp7!,Temp!)
             Call Dot.Display(VarD,VarE,VarF!)
             If Temp6!=SFalse Then
                Exit Do
             Endif
             Temp5!=Temp6!
          Loop
       Endif
    Next
    Call IO.O
    Graphics.Off=False
    Strng="Room inventory file packed."
    Call IO.O
 Endif
 Strng="Pack room description file(y/n)? "
 Line.Length=TempD
 No.Input.Out="Y"
 Call IO.I
 If Yes Then
    Carriage.Return=True
    Graphics.Off=True
    Strng="Making backup of room description file"
    Call IO.O
    Close #TempFile1
    FileName=Data.Path1+"ROOMDESC.BAK"
    If Dir$(FileName)<>Nul Then
       Kill FileName
    Endif
    VarD=False
    VarE=False
    VarF!=Timeit!
    Open FileName For Random Shared As #TempFile1 Len=RoomDescLen
    For Var5!=1! To Lof(RoomDescFile)/RoomDescLen
       Call Read.Record(RoomDescFile,Var5!)
       Call Write.TempFile(8,Var5!)
       Call Dot.Display(VarD,VarE,VarF!)
    Next
    Call IO.O
    Carriage.Return=True
    Strng="Packing room description file"
    Call IO.O
    Close #RoomDescFile
    FileName=Room.Desc.FileName
    If Dir$(FileName)<>Nul Then
       Kill FileName
    Endif
    VarD=False
    VarE=False
    VarF!=Timeit!
    Temp5!=SFalse
    Open FileName For Random Shared As #RoomDescFile Len=RoomDescLen
    For Var!=1! To Lof(RoomFile)/RoomRecLen
       Call Read.Record(RoomFile,Var!)
       For Temp5=1 To 19
          Var6!=RoomRecord.LongDesc(Temp5)
          If Var6!>SFalse And Var6!<=Lof(TempFile1)/RoomDescLen Then
             Call Read.TempFile(8,Var6!)
             Temp5!=Temp5!+1!
             Call Write.Record(RoomDescFile,Temp5!)
             RoomRecord.LongDesc(Temp5)=Temp5!
          Endif
          Call Dot.Display(VarD,VarE,VarF!)
       Next
       Call Write.Record(RoomFile,Var!)
       Call Dot.Display(VarD,VarE,VarF!)
    Next
    Call IO.O
    Graphics.Off=False
    Strng="Room description file packed."
    Call IO.O
 Endif
ErrExit65:
 Exit Sub
ErrResume65:
 Resume ErrExit65
End Sub

Sub Repair.Rooms(VarK)
 On Local Error Goto ErrResume65a
 Call Search.Mess2(Var2)
 If Var2 Then
    Strng="Can't repair while node/user online."
    Call IO.O
    Exit Sub
 Endif
 If VarK Then
    Strng="Repair room inventory file(y/n)? "
    Line.Length=TempD
    No.Input.Out="Y"
    Call IO.I
    If No Then
       Exit Sub
    Endif
 Endif
 Carriage.Return=True
 Graphics.Off=True
 Strng="Making backup of room inventory file"
 Call IO.O
 Close #TempFile1
 FileName=Data.Path1+"ROOMINV2.BAK"
 If Dir$(FileName)<>Nul Then
    Kill FileName
 Endif
 VarD=False
 VarE=False
 VarF!=Timeit!
 Open FileName For Random Shared As #TempFile1 Len=MessWorkRecLen6
 For Temp5!=1! To Lof(RoomInvFile)/MessWorkRecLen6
    Call Read.Record(RoomInvFile,Temp5!)
    Call Write.TempFile(7,Temp5!)
    Call Dot.Display(VarD,VarE,VarF!)
 Next
 Call IO.O
 Carriage.Return=True
 Graphics.Off=True
 Strng="Repairing room inventory file"
 Call IO.O
 VarD=False
 VarE=False
 VarF!=Timeit!
 Temp5!=SFalse
 VarZ1!=SFalse
 For Temp1!=1! To Lof(RoomFile)/RoomRecLen
    Call Dot.Display(VarD,VarE,VarF!)
    Call Read.Record(RoomFile,Temp1!)
    Temp2!=RoomRecord.First
    Temp3!=RoomRecord.Last
    If Temp2!>SFalse And Temp3!>SFalse Then
       If Temp2!=Temp3! Then
          Call Read.Record(RoomInvFile,Temp2!)
          If MessWorkRecord6.Prev<>SFalse Or MessWorkRecord6.Next<>SFalse Then
             VarZ1!=VarZ1!+1!
             MessWorkRecord6.Prev=SFalse
             MessWorkRecord6.Next=SFalse
             Call Write.Record(RoomInvFile,Temp2!)
          Endif
       Else
          Call Read.Record(RoomInvFile,Temp2!)
          If MessWorkRecord6.Prev<>SFalse Then
             VarZ1!=VarZ1!+1!
             MessWorkRecord6.Prev=SFalse
             Call Write.Record(RoomInvFile,Temp2!)
          Endif
          Call Read.Record(RoomInvFile,Temp3!)
          If MessWorkRecord6.Next<>SFalse Then
             VarZ1!=VarZ1!+1!
             MessWorkRecord6.Next=SFalse
             Call Write.Record(RoomInvFile,Temp3!)
          Endif
       Endif
    Endif
 Next
 VarZ2!=SFalse
 Close #TempFile1
 FileName=GetFilename$("TABLE","BK3")
 Open FileName For Random Shared As #TempFile1 Len=4
 Field #TempFile1,4 As S$
 For Temp1!=1! To Lof(RoomFile)/RoomRecLen
    VarY1!=0!
    Call Dot.Display(VarD,VarE,VarF!)
    Call Read.Record(RoomFile,Temp1!)
    Temp2!=RoomRecord.First
    If Temp2! Then
       Do
          Call Read.Record(RoomInvFile,Temp2!)
          VarY1!=VarY1!+1!
          Lset S$=Mks$(Temp2!)
          Put #TempFile1,VarY1!
          Temp6!=MessWorkRecord6.Next
          If Temp6!>SFalse Then
             Call Read.Record(RoomInvFile,Temp6!)
             For Temp7!=1! To VarY1!
                Get #TempFile1,Temp7!
                Temp8!=Cvs(S$)
                If Temp6!=Temp8! Then
                   Gosub Truncate1
                   Exit Do
                Endif
             Next
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Next
 For Temp1!=1! To Lof(RoomFile)/RoomRecLen
    VarY1!=0!
    Call Dot.Display(VarD,VarE,VarF!)
    Call Read.Record(RoomFile,Temp1!)
    Temp2!=RoomRecord.Last
    If Temp2! Then
       Do
          Call Read.Record(RoomInvFile,Temp2!)
          VarY1!=VarY1!+1!
          Lset S$=Mks$(Temp2!)
          Put #TempFile1,VarY1!
          Temp6!=MessWorkRecord6.Prev
          If Temp6!>SFalse Then
             Call Read.Record(RoomInvFile,Temp6!)
             For Temp7!=1! To VarY1!
                Get #TempFile1,Temp7!
                Temp8!=Cvs(S$)
                If Temp6!=Temp8! Then
                   Gosub Truncate2
                   Exit Do
                Endif
             Next
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Next
 Close #TempFile1
 Kill Filename
 For Temp1!=1! To Lof(RoomFile)/RoomRecLen
    Call Dot.Display(VarD,VarE,VarF!)
    Call Read.Record(RoomFile,Temp1!)
    Temp2!=RoomRecord.First
    If Temp2! Then
       Do
          Call Read.Record(RoomInvFile,Temp2!)
          Temp6!=MessWorkRecord6.Next
          If Temp6!>SFalse Then
             Call Read.Record(RoomInvFile,Temp6!)
             If Temp2!<>MessWorkRecord6.Prev Then
                Gosub Truncate1
                Exit Do
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Next
 For Temp1!=1! To Lof(RoomFile)/RoomRecLen
    Call Dot.Display(VarD,VarE,VarF!)
    Call Read.Record(RoomFile,Temp1!)
    Temp2!=RoomRecord.Last
    If Temp2! Then
       Do
          Call Read.Record(RoomInvFile,Temp2!)
          Temp6!=MessWorkRecord6.Prev
          If Temp6!>SFalse Then
             Call Read.Record(RoomInvFile,Temp6!)
             If Temp2!<>MessWorkRecord6.Next Then
                Gosub Truncate2
                Exit Do
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Next
 VarZ3!=SFalse
 For Temp1!=1! To Lof(RoomFile)/RoomRecLen
    Call Dot.Display(VarD,VarE,VarF!)
    Call Read.Record(RoomFile,Temp1!)
    Temp2!=RoomRecord.First
    If Temp2! Then
       Do
          Call Read.Record(RoomInvFile,Temp2!)
          Temp6!=MessWorkRecord6.Next
          Temp3!=MessWorkRecord6.Room
          If Temp3!<>Temp1! Then
             VarZ3!=VarZ3!+1!
             MessWorkRecord6.Room=Temp1!
             Call Write.Record(RoomInvFile,Temp2!)
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Next
 Call IO.O
 Graphics.Off=False
 Strng="Room inventory file repaired."
 Call IO.O
 Strng="Reset"+Str$(VarZ1!)+" nodes."
 Call IO.O
 Strng="Deleted"+Str$(VarZ2!)+" nodes."
 Call IO.O
 Strng="Repaired"+Str$(VarZ3!)+" nodes."
 Call IO.O
 Exit Sub
Truncate1:
 VarZ2!=VarZ2!+1!
 Call Read.Record(RoomInvFile,Temp2!)
 MessWorkRecord6.Next=SFalse
 Call Write.Record(RoomInvFile,Temp2!)
 RoomRecord.Last=Temp2!
 Call Write.Record(RoomFile,Temp1!)
 Return
Truncate2:
 VarZ2!=VarZ2!+1!
 Call Read.Record(RoomInvFile,Temp2!)
 MessWorkRecord6.Prev=SFalse
 Call Write.Record(RoomInvFile,Temp2!)
 RoomRecord.First=Temp2!
 Call Write.Record(RoomFile,Temp1!)
 Return
ErrExit65a:
 Exit Sub
ErrResume65a:
 Resume ErrExit65a
End Sub

' add container to rooms.dat list
Sub Add.Container.To.Room
 On Local Error Goto ErrResume141f
 VarA!=Lof(ContainerFile)/ContainerRecLen+1!
 Call Clear.Container2
 Strng="Invisible container(y/n)? "
 Line.Length=TempD
 No.Input.Out="N"
 Call IO.I
 ContainerRecord.InvisibleContainer=Yes
 For VarR=1 To 3
    ContainerRecord.RestrictItem(VarR)=TreasureRecord.RestrictItem(VarR)
 Next
 ContainerRecord.ContainerName=TreasureRecord.TreasureName
 ContainerRecord.ContainerShort=TreasureRecord.ShortName
 ContainerRecord.ContainerMax=TreasureRecord.ContainerMax
 ContainerRecord.NamePrefix=TreasureRecord.ContainerPrefix
 ContainerRecord.Prefix1=TreasureRecord.Prefix1
 ContainerRecord.Size=TreasureRecord.ContainerSize
 ContainerRecord.Material=TreasureRecord.ContainerMaterial
 If TreasureRecord.KeyNumber Then
    ContainerRecord.KeyNumber=TreasureRecord.KeyNumber
    ContainerRecord.Closed=True
    ContainerRecord.Locked=True
 Endif
 If TreasureRecord.Locked Then
    ContainerRecord.Closed=True
    ContainerRecord.Locked=True
 Endif
 ContainerRecord.RoomNumber=Temp!
 ContainerRecord.UserNumber=0!
 ContainerRecord.WithinContainer=SFalse
 ContainerRecord.Weight=TreasureRecord.Weight
 ContainerRecord.ContainerIndex=TempC!
 ContainerRecord.Disappears=TreasureRecord.ContainerDisappears
 ContainerRecord.SelfImplodes=TreasureRecord.ContainerSelfImplodes
 ContainerRecord.Permanent=TreasureRecord.Permanent
 ContainerRecord.First=SFalse
 ContainerRecord.Last=SFalse
 ContainerRecord.SwapFlag=SFalse
 ContainerRecord.Scanned=False
 Call Write.Record(ContainerFile,VarA!)
 Call Read.Record(RoomFile,Temp!)
 If RoomRecord.First2=SFalse Then
    RoomRecord.First2=VarA!
    RoomRecord.Last2=VarA!
    Call Write.Record(RoomFile,Temp!)
    ContainerRecord.Prev=SFalse
    ContainerRecord.Next=SFalse
    Call Write.Record(ContainerFile,VarA!)
 Else
    ContainerRecord.Prev=RoomRecord.Last2
    ContainerRecord.Next=SFalse
    Call Write.Record(ContainerFile,VarA!)
    Call Read.Record(ContainerFile,RoomRecord.Last2)
    ContainerRecord.Next=VarA!
    Call Write.Record(ContainerFile,RoomRecord.Last2)
    Call Read.Record(ContainerFile,VarA!)
    RoomRecord.Last2=VarA!
    Call Write.Record(RoomFile,Temp!)
 Endif
ErrExit141f:
 Exit Sub
ErrResume141f:
 Resume ErrExit141f
End Sub

Sub Clear.Container2
 On Local Error Goto ErrResume116b
 ContainerRecord.ContainerName=Nul
 ContainerRecord.ContainerShort=Nul
 ContainerRecord.NamePrefix="in it"
 ContainerRecord.ContainerMax=False
 ContainerRecord.Closed=False
 ContainerRecord.Locked=False
 ContainerRecord.KeyNumber=SFalse
 ContainerRecord.UserNumber=SFalse
 ContainerRecord.RoomNumber=SFalse
 ContainerRecord.DeletedContainer=False
 ContainerRecord.InvisibleContainer=False
 ContainerRecord.Weight=False
 ContainerRecord.WithinContainer=SFalse
 ContainerRecord.Disappears=SFalse
 ContainerRecord.ContainerIndex=SFalse
 ContainerRecord.Size=False
 ContainerRecord.Material=False
 ContainerRecord.Permanent=False
 ContainerRecord.SelfImplodes=False
 ContainerRecord.TrapType=False
 ContainerRecord.TrapHits=False
 ContainerRecord.TrapItem=SFalse
 ContainerRecord.First2=SFalse
 ContainerRecord.Last2=SFalse
 ContainerRecord.First=SFalse
 ContainerRecord.Last=SFalse
 ContainerRecord.Prev=SFalse
 ContainerRecord.Next=SFalse
 ContainerRecord.Prefix1=""
 ContainerRecord.Damaged=False
 ContainerRecord.Scanned=False
ErrExit116b:
 Exit Sub
ErrResume116b:
 Resume ErrExit116b
End Sub

Sub Delete.Room.Container(VarZ!,Var2!)
 On Local Error Goto ErrorTrp32d
 If RoomRecord.First2=VarZ! Then
    Call Read.Record(ContainerFile,VarZ!)
    RoomRecord.First2=ContainerRecord.Next
    Call Write.Record(RoomFile,Var2!)
    If RoomRecord.First2>SFalse Then
       Call Read.Record(ContainerFile,RoomRecord.First2)
       ContainerRecord.Prev=SFalse
       Call Write.Record(ContainerFile,RoomRecord.First2)
    Endif
 Else
    If RoomRecord.Last2=VarZ! Then
       Call Read.Record(ContainerFile,VarZ!)
       RoomRecord.Last2=ContainerRecord.Prev
       Call Write.Record(RoomFile,Var2!)
       If RoomRecord.Last2>SFalse Then
          Call Read.Record(ContainerFile,RoomRecord.Last2)
          ContainerRecord.Next=SFalse
          Call Write.Record(ContainerFile,RoomRecord.Last2)
       Endif
    Else
       Call Read.Record(ContainerFile,VarZ!)
       Previous.Node!=ContainerRecord.Prev
       Next.Node!=ContainerRecord.Next
       Call Read.Record(ContainerFile,Previous.Node!)
       ContainerRecord.Next=Next.Node!
       Call Write.Record(ContainerFile,Previous.Node!)
       Call Read.Record(ContainerFile,Next.Node!)
       ContainerRecord.Prev=Previous.Node!
       Call Write.Record(ContainerFile,Next.Node!)
    Endif
 Endif
ErrorRsm32d:
 Exit Sub
ErrorTrp32d:
 Resume ErrorRsm32d
End Sub

Sub Clear.Container.Node
 On Local Error Goto ErrorTrp32c
 ContainerRecord.UserNumber=SFalse
 ContainerRecord.RoomNumber=SFalse
 ContainerRecord.DeletedContainer=True
 ContainerRecord.Prev=SFalse
 ContainerRecord.Next=SFalse
ErrorRsm32c:
 Exit Sub
ErrorTrp32c:
 Resume ErrorRsm32c
End Sub

Sub Add.List.Node(VarZ!,Var2!)
 On Local Error Goto ErrorTrp27a
 Call Read.Record(RoomFile,Var2!)
 If RoomRecord.First=SFalse Then
    RoomRecord.First=VarZ!
    RoomRecord.Last=VarZ!
    Call Write.Record(RoomFile,Var2!)
    MessWorkRecord6.Prev=SFalse
    MessWorkRecord6.Next=SFalse
    Call Write.Record(RoomInvFile,VarZ!)
    Exit Sub
 Endif
 MessWorkRecord6.Prev=RoomRecord.Last
 MessWorkRecord6.Next=SFalse
 Call Write.Record(RoomInvFile,VarZ!)
 Call Read.Record(RoomInvFile,RoomRecord.Last)
 MessWorkRecord6.Next=VarZ!
 Call Write.Record(RoomInvFile,RoomRecord.Last)
 Call Read.Record(RoomInvFile,VarZ!)
 RoomRecord.Last=VarZ!
 Call Write.Record(RoomFile,Var2!)
ErrorRsm27a:
 Exit Sub
ErrorTrp27a:
 Resume ErrorRsm27a
End Sub
