 Rem File: Train.bas - for Cmd*.bas modules
 Rem $Include: 'dndbbs.inc'
Sub Train
 On Local Error Goto ErrTrap17
 If UserRecord.Level<=False Then ' user is dead
    Call Train.Stats ' free train
    Exit Sub
 Endif
 If UserRecord.Level=MaxInt Then ' user is maxed out
    Strng="Nothing happens!"
    Call IO.O
    Exit Sub
 Endif
 Call Gold(Temp#)
 If UserRecord.Gold<Temp# Then
    Strng="You don't have enough Gold to train!"
    Call IO.O
    Exit Sub
 Endif
 If Config2(44) Then
    If Config2(93)=False Then
       If UserRecord.Experience>False Then
          Strng="You don't have enough experience to train!"
          Call IO.O
          Exit Sub
       Endif
    Else
       Call Experience(Temp#)
       If UserRecord.Experience<Temp# Then
          Strng="You don't have enough experience to train!"
          Call IO.O
          Exit Sub
       Endif
    Endif
 Endif
 If Config2(44)=False Then ' room is required
    Call In.Room(UserRecord.ClassType)
    If TempA=False Then
       Strng="You can't train here!"
       Call IO.O
       Strng="Train in room "+Rtrim$(Room.Array(UserRecord.ClassType))+"."
       Call IO.O
       Exit Sub
    Endif
 Endif
 Call Train.Stats
ErrResume17:
 Exit Sub
ErrTrap17:
 Resume ErrResume17
End Sub

Sub Train2
 On Local Error Goto ErrTrap17x
 If UserRecord2.Level<=False Then
    Call Train.Stats2
    Exit Sub
 Endif
 If UserRecord2.Level=MaxInt Then
    Exit Sub
 Endif
 Call Gold2(Temp#)
 If UserRecord2.Gold<Temp# Then
    Exit Sub
 Endif
 If Config2(44) Then
    If Config2(93)=False Then
       If UserRecord2.Experience>False Then
          Exit Sub
       Endif
    Else
       Call Experience2(Temp#)
       If UserRecord2.Experience<Temp# Then
          Exit Sub
       Endif
    Endif
 Endif
 If Config2(44)=False Then
    Call In.Room(UserRecord2.ClassType)
    If TempA=False Then
       Exit Sub
    Endif
 Endif
 Call Train.Stats2
ErrResume17x:
 Exit Sub
ErrTrap17x:
 Resume ErrResume17x
End Sub

Sub Gold2(Var#)
 On Local Error Goto ErrTrap17y
 Var1#=Config2(91)+Config2(94)
 Var2#=2^Var1#
 If UserRecord2.Level<=Config2(94) Then
    Var#=2^(UserRecord2.Level+Config2(91))
 Else
    Var#=Var2#+(UserRecord2.Level-Config2(94))*Config1(31)
 Endif
ErrResume17y:
 Exit Sub
ErrTrap17y:
 Resume ErrResume17y
End Sub

Sub Train.Stats
 On Local Error Goto ErrorTrp38
 If UserRecord.Level<False Then
    UserRecord.Level=False
 Endif
 If UserRecord.Level>=MaxInt Then
    Strng="Nothing happens.."
    Call IO.O
    Exit Sub
 Endif
 If UserRecord.Level>False Then
    Call Gold(Temp#)
    UserRecord.Gold=UserRecord.Gold-Temp#
    If UserRecord.Gold<False Then
       UserRecord.Gold=False
    Endif
 Endif
 Graphics.Off=False
 Strng="After many hours of training and meditation..."
 Call IO.O
 Graphics.Off=True
 Temp1=Int(Rnd*7+1)
 If UserRecord.Stats(Temp1)<MaxInt Then
    UserRecord.Stats(Temp1)=UserRecord.Stats(Temp1)+1
    Out2=Stat(Temp1)
    Out2=Rtrim$(Out2)
    Out2=Lcase$(Out2)
    Strng="gained one "+Out2+" point"
    Call Update.DayFile(Strng,False,2)
    Strng="You "+Lcase$(Strng)+"!"
    Call IO.O
 Endif
 If UserRecord.Level<=5 Then
    If UserRecord.Stats(6)<MaxInt Then
       UserRecord.Stats(6)=UserRecord.Stats(6)+1
       Out2=Stat(6)
       Out2=Rtrim$(Out2)
       Out2=Lcase$(Out2)
       Strng="gained one "+Out2+" point"
       Call Update.DayFile(Strng,False,2)
       Strng="You "+Lcase$(Strng)+"!"
       Call IO.O
    Endif
 Endif
 If UserRecord.Level<MaxInt Then
    UserRecord.Level=UserRecord.Level+1
 Endif
 Call Write.Record(UserFile,User.Index)
 Call New.Stats
 UserRecord.Experience=False
 If Config2(93)=False Then
    Call Experience(Temp#)
    UserRecord.Experience=Temp#
 Endif
 Strng="trained for level"
 If UserRecord.Level>10 Then
    Strng=Strng+Str$(UserRecord.Level)
 Else
    Strng=Strng+" "+Rtrim$(Numeral(UserRecord.Level))
 Endif
 Call Update.DayFile(Strng,False,1)
 Graphics.Off=False
 Strng=UserRecord.CodeName
 Strng=Rtrim$(Strng)
 Strng=Lcase$(Strng)
 Mid$(Strng,1,1)=Ucase$(Mid$(Strng,1,1))
 Strng="Information: "+Strng+"."
 Call IO.O
 Graphics.Off=True
 Call Show.Align
 Call Show.Health
 Call Display.Experience
ErrorRsm38:
 Exit Sub
ErrorTrp38:
 Resume ErrorRsm38
End Sub

Sub Train.Stats2
 On Local Error Goto ErrorTrp17z
 If UserRecord2.ClassType=AsstDM Or UserRecord2.Level>999 Then
    Var1=True
 Else
    Var1=False
 Endif
 If UserRecord2.ClassType=DM Or UserRecord2.Level>9999 Then
    Var2=True
 Else
    Var2=False
 Endif
 If UserRecord2.Flags And Special.Char4 Then
    Var3=True
 Else
    Var3=False
 Endif
 If Var1 Or Var2 Or Var3 Then
    Normal.User2=False
 Else
    Normal.User2=True
 Endif
 If UserRecord2.Level<False Then
    UserRecord2.Level=False
 Endif
 If UserRecord2.Level>=MaxInt Then
    Exit Sub
 Endif
 If UserRecord2.Level>False Then
    Call Gold2(Temp#)
    UserRecord2.Gold=UserRecord2.Gold-Temp#
    If UserRecord2.Gold<False Then
       UserRecord2.Gold=False
    Endif
 Endif
 Graphics.Off=True
 Temp1=Int(Rnd*7+1)
 If UserRecord2.Stats(Temp1)<MaxInt Then
    UserRecord2.Stats(Temp1)=UserRecord2.Stats(Temp1)+1
    Strng=Stat(Temp1)
    Strng=Rtrim$(Strng)
    Strng=Lcase$(Strng)
    Out2="You gained one "+Strng+" point in offline team player fighting"
    Temp2!=MessWorkRecord4.Index
    Call Update.Logfile(Out2,Temp2!)
    Strng=Out4+" gained one "+Strng+" point."
    Call IO.O
 Endif
 If UserRecord2.Level<=5 Then
    If UserRecord2.Stats(6)<MaxInt Then
       UserRecord2.Stats(6)=UserRecord2.Stats(6)+1
       Strng=Stat(6)
       Strng=Rtrim$(Strng)
       Strng=Lcase$(Strng)
       Out2="You gained one "+Strng+" point in offline team player fighting"
       Temp2!=MessWorkRecord4.Index
       Call Update.Logfile(Out2,Temp2!)
       Strng=Out4+" gained one "+Strng+" point."
       Call IO.O
    Endif
 Endif
 UserRecord2.Level=UserRecord2.Level+1
 Call New.Stats2(Var5)
 UserRecord2.Experience=False
 If Config2(93)=False Then
    Call Experience2(Temp#)
    UserRecord2.Experience=Temp#
 Endif
 If UserRecord2.Level>10 Then
    Strng=Form$(Cdbl(UserRecord2.Level))
 Else
    Strng=Rtrim$(Numeral(UserRecord2.Level))
 Endif
 Out2="You trained for level "+Strng+" in offline team player fighting"
 Temp2!=MessWorkRecord4.Index
 Call Update.Logfile(Out2,Temp2!)
 Strng=Out4+" trained for level "+Strng+"."
 Call IO.O
ErrorRsm17z:
 Exit Sub
ErrorTrp17z:
 Resume ErrorRsm17z
End Sub

Sub New.Stats
 On Local Error Goto ErrorTrp39
 If UserRecord.Level<False Then
    UserRecord.Level=False
 Endif
 Temp#=Cdbl(Training.Stats(UserRecord.ClassType,1))*Cdbl(UserRecord.Level)
 If Temp#>MaxInt Then
    Temp#=MaxInt
 Endif
 UserRecord.FatigueMax=Cint(Temp#)
 Temp#=Cdbl(Training.Stats(UserRecord.ClassType,2))*Cdbl(UserRecord.Level)
 If Temp#>MaxInt Then
    Temp#=MaxInt
 Endif
 UserRecord.VitalityMax=Cint(Temp#)
 Temp#=Cdbl(Training.Stats(UserRecord.ClassType,3))*Cdbl(UserRecord.Level)
 If Temp#>MaxInt Then
    Temp#=MaxInt
 Endif
 UserRecord.MagicMax=Cint(Temp#)
 Temp#=Cdbl(Training.Stats(UserRecord.ClassType,4))*Cdbl(UserRecord.Level)
 If Temp#>MaxInt Then
    Temp#=MaxInt
 Endif
 UserRecord.PsionicMax=Cint(Temp#)
 If UserRecord.Fatigue<False Or _
 UserRecord.Fatigue>UserRecord.FatigueMax Then
    UserRecord.Fatigue=UserRecord.FatigueMax
 Endif
 If UserRecord.Vitality<False Or UserRecord.Vitality>UserRecord.VitalityMax Then
    UserRecord.Vitality=UserRecord.VitalityMax
 Endif
 If UserRecord.Magic<False Or UserRecord.Magic>UserRecord.MagicMax Then
    UserRecord.Magic=UserRecord.MagicMax
 Endif
 If UserRecord.Psionic<False Or UserRecord.Psionic>UserRecord.PsionicMax Then
    UserRecord.Psionic=UserRecord.PsionicMax
 Endif
 If Normal.User Then
    For Temp=1 To MaxStats
       If UserRecord.Stats(Temp)>Config2(31) Then
          UserRecord.Stats(Temp)=Config2(31)
          Strng=Lcase$(Rtrim$(Stat(Temp)))
          Mid$(Strng,1,1)=Ucase$(Mid$(Strng,1,1))
          Strng="Your "+Strng+" is reset to"+Str$(Config2(31))+"."
          Call IO.O
       Endif
    Next
 Endif
 Call Status.Line(False)
 If Normal.User Then
    Var=False
    For Var1=1 To MaxStats
       If UserRecord.Stats(Var1)<=False Then
          Var=True
          Out2=Stat(Var1)
          Out2=Rtrim$(Out2)
          Out2=Lcase$(Out2)
          Strng="Your "+Out2+" is zero!"
          Call IO.O
          UserRecord.Stats(Var1)=1
       Endif
    Next
    If Var Then
       Strng="died from low stats"
       Call Update.DayFile(Strng,False,1)
       Message1="You died from low statistics!"
       Call Player.Died
       Exit Sub
    Endif
 Endif
 If Config2(48) Then
    If UserRecord.Level>=10 Then
       If UserRecord.ClassType>=Fighter And UserRecord.ClassType<AsstDM Then
          Var1$=Lcase$(Rtrim$(UserRecord.ClassName))
          If Var1$=Lcase$(Rtrim$(Class.Name(UserRecord.ClassType))) Then
             Var2$=Lcase$(Rtrim$(High.Class.Name(UserRecord.ClassType)))
             If Len(Var2$) Then
                Call Valid(Var2$,20)
                If Var2$=Nul Then
                   Eat$=Nul
                Else
                   Var2$=Rtrim$(Var2$)
                   If Var1$<>Var2$ Then
                      Call Capitalize(Var2$)
                      UserRecord.ClassName=Var2$
                      Strng="Your classname was upgraded to "+Var2$+"."
                      Call IO.O
                   Endif
                Endif
             Endif
          Endif
       Endif
    Endif
 Endif
 Call Get.User.Stats(Temp)
 If Temp=False Then
    Call Hang.Up(12)
 Endif
ErrorRsm39:
 Exit Sub
ErrorTrp39:
 Resume ErrorRsm39
End Sub

Sub New.Stats2(Var5)
 On Local Error Goto ErrorTrp17z1
 If Len(Out4) Then
    Mid$(Out4,1,1)=Ucase$(Mid$(Out4,1,1))
 Endif
 Var5=False
 If UserRecord2.ClassType=AsstDM Or UserRecord2.Level>999 Then
    Var1=True
 Else
    Var1=False
 Endif
 If UserRecord2.ClassType=DM Or UserRecord2.Level>9999 Then
    Var2=True
 Else
    Var2=False
 Endif
 If UserRecord2.Flags And Special.Char4 Then
    Var3=True
 Else
    Var3=False
 Endif
 If Var1 Or Var2 Or Var3 Then
    Normal.User2=False
 Else
    Normal.User2=True
 Endif
 If UserRecord2.Level<False Then
    UserRecord2.Level=False
 Endif
 Temp#=Cdbl(Training.Stats(UserRecord2.ClassType,1))*Cdbl(UserRecord2.Level)
 If Temp#>MaxInt Then
    Temp#=MaxInt
 Endif
 UserRecord2.FatigueMax=Cint(Temp#)
 Temp#=Cdbl(Training.Stats(UserRecord2.ClassType,2))*Cdbl(UserRecord2.Level)
 If Temp#>MaxInt Then
    Temp#=MaxInt
 Endif
 UserRecord2.VitalityMax=Cint(Temp#)
 Temp#=Cdbl(Training.Stats(UserRecord2.ClassType,3))*Cdbl(UserRecord2.Level)
 If Temp#>MaxInt Then
    Temp#=MaxInt
 Endif
 UserRecord2.MagicMax=Cint(Temp#)
 Temp#=Cdbl(Training.Stats(UserRecord2.ClassType,4))*Cdbl(UserRecord2.Level)
 If Temp#>MaxInt Then
    Temp#=MaxInt
 Endif
 UserRecord2.PsionicMax=Cint(Temp#)
 If UserRecord2.Fatigue<False Or _
 UserRecord2.Fatigue>UserRecord2.FatigueMax Then
    UserRecord2.Fatigue=UserRecord2.FatigueMax
 Endif
 If UserRecord2.Vitality<False Or UserRecord2.Vitality>UserRecord2.VitalityMax Then
    UserRecord2.Vitality=UserRecord2.VitalityMax
 Endif
 If UserRecord2.Magic<False Or UserRecord2.Magic>UserRecord2.MagicMax Then
    UserRecord2.Magic=UserRecord2.MagicMax
 Endif
 If UserRecord2.Psionic<False Or UserRecord2.Psionic>UserRecord2.PsionicMax Then
    UserRecord2.Psionic=UserRecord2.PsionicMax
 Endif
 If Normal.User2 Then
    For Temp=1 To MaxStats
       If UserRecord2.Stats(Temp)>Config2(31) Then
          UserRecord2.Stats(Temp)=Config2(31)
          Strng=Lcase$(Rtrim$(Stat(Temp)))
          Mid$(Strng,1,1)=Ucase$(Mid$(Strng,1,1))
          Strng=Out4+"'s "+Strng+" is reset to"+Str$(Config2(31))+"."
          Call IO.O
       Endif
    Next
 Endif
 If Normal.User2 Then
    Var=False
    For Var1=1 To MaxStats
       If UserRecord2.Stats(Var1)<=False Then
          Var=True
          Out2=Stat(Var1)
          Out2=Rtrim$(Out2)
          Out2=Lcase$(Out2)
          Strng=Out4+"'s "+Out2+" is zero!"
          Call IO.O
          UserRecord2.Stats(Var1)=1
       Endif
    Next
    If Var Then
       Strng=Out4+" died from low stats."
       Call IO.O
       Out2="You died from low stats in offline team player fighting"
       Temp2!=MessWorkRecord4.Index
       Call Update.Logfile(Out2,Temp2!)
       MessWorkRecord4.Room=Int(Val(Config3(24))+.5)
       Call Write.Record(MessWorkFile4,User.Temp)
       UserRecord2.Room=Int(Val(Config3(24))+.5)
       Call Write.Record(UserFile2,MessWorkRecord4.Index)
       Var5=True
       Exit Sub
    Endif
 Endif
 If Config2(48) Then
    If UserRecord2.Level>=10 Then
       If UserRecord2.ClassType>=Fighter And UserRecord2.ClassType<AsstDM Then
          Var1$=Lcase$(Rtrim$(UserRecord2.ClassName))
          If Var1$=Lcase$(Rtrim$(Class.Name(UserRecord2.ClassType))) Then
             Var2$=Lcase$(Rtrim$(High.Class.Name(UserRecord2.ClassType)))
             If Len(Var2$) Then
                Call Valid(Var2$,20)
                If Var2$=Nul Then
                   Eat$=Nul
                Else
                   Var2$=Rtrim$(Var2$)
                   If Var1$<>Var2$ Then
                      Call Capitalize(Var2$)
                      UserRecord2.ClassName=Var2$
                      Strng=Out4+"'s classname was upgraded to "+Var2$+"."
                      Call IO.O
                      Out2="Your classname was upgraded in offline team player fighting"
                      Temp2!=MessWorkRecord4.Index
                      Call Update.Logfile(Out2,Temp2!)
                   Endif
                Endif
             Endif
          Endif
       Endif
    Endif
 Endif
ErrorRsm17z1:
 Exit Sub
ErrorTrp17z1:
 Resume ErrorRsm17z1
End Sub

Sub Get.User.Stats(Var)
 On Local Error Goto ErrorTrp53
 Var=True
 If UserRecord.Flags And Special.Char1 Then
    Town.Mayor=True
 Else
    Town.Mayor=False
 Endif
 If UserRecord.Flags And Special.Char2 Then
    Governor=True
 Else
    Governor=False
 Endif
 If UserRecord.Flags And Special.Char3 Then
    Guild.Master=True
 Else
    Guild.Master=False
 Endif
 If UserRecord.ClassType=AsstDM Or UserRecord.Level>999 Then
    Dungeon.Master.Assistant=True
 Else
    Dungeon.Master.Assistant=False
 Endif
 If UserRecord.ClassType=DM Or UserRecord.Level>9999 Then
    Dungeon.Master=True
 Else
    Dungeon.Master=False
 Endif
 If UserRecord.Flags And Special.Char4 Then
    Sysop=True
 Else
    Sysop=False
 Endif
 If Dungeon.Master Or Dungeon.Master.Assistant Or Sysop Then
    Normal.User=False
 Else
    Normal.User=True
 Endif
 If Disable.DM Then
    If Dungeon.Master Or Dungeon.Master.Assistant Then
       Var=False
    Endif
 Endif
 If Disable.Sysop Then
    If Sysop Then
       Var=False
    Endif
 Endif
 If Normal.User Then
    Debug.Mode=False
 Endif
ErrorRsm53:
 Exit Sub
ErrorTrp53:
 Resume ErrorRsm53
End Sub

Sub Numeric
 On Local Error Goto ErrorTrp6
 Var=False
 Var1=Instr(Parsed.Command1,"#")
 If Var1 Then
    Var=Int(Val(Mid$(Parsed.Command1,Var1+1))+.5)
    Parsed.Command1=Left$(Parsed.Command1,Var1-1)
 Endif
 Parse.Temp=Var
ErrorRsm6:
 Exit Sub
ErrorTrp6:
 Resume ErrorRsm6
End Sub

Sub Parse
 On Local Error Goto ErrorTrp8
 Var=Instr(Parsed.Command2," ")
 Parser=False
 If Var Then
    Parsed.Command1=Left$(Parsed.Command2,Var-1)
    Parsed.Command2=Mid$(Parsed.Command2,Var+1)
    Parser=Var
 Endif
ErrorRsm8:
 Exit Sub
ErrorTrp8:
 Resume ErrorRsm8
End Sub

Sub ParseX
 On Local Error Goto ErrorTrp9
 Var=Instr(Parsed.Command2," ")
 Parser=False
 If Var Then
    Parsed.Command1=Mid$(Parsed.Command2,Var+1)
    Parsed.Command2=Left$(Parsed.Command2,Var-1)
    Parser=Var
 Endif
ErrorRsm9:
 Exit Sub
ErrorTrp9:
 Resume ErrorRsm9
End Sub

' check room for object/treasure
Sub Check.Room.Items
 On Local Error Goto ErrorTrp14
 Temp6=False
 Temp7!=SFalse
 TempC=False
 If Parsed.Command1<>Nul Then
    Temp5!=RoomRecord.First
    If Temp5! Then
       Do While Lost.Carrier=False
          Call Read.Record(RoomInvFile,Temp5!)
          If MessWorkRecord6.Room=SFalse Then
             Exit Do
          Endif
          Temp6!=MessWorkRecord6.Next
          TempA!=MessWorkRecord6.Index
          If TempA!<SFalse Then
             VarA!=Abs(TempA!)
             If VarA!>SFalse And VarA!<=Lof(ObjectFile)/ObjectRecLen Then
                Call Read.Record(ObjectFile,VarA!)
                Out3=ObjectRecord.ShortName
                Out3=Left$(Out3,Len(Parsed.Command1))
                If Out3=Parsed.Command1 Then
                   TempC=TempC+1
                   If Parse.Temp=False Or TempC=Parse.Temp Then
                      Out3=ObjectRecord.ObjectName
                      Out3=Rtrim$(Out3)
                      Temp7!=TempA!
                      Temp6=MessWorkRecord6.Charges
                      Exit Do
                   Endif
                Endif
             Endif
          Endif
          If TempA!>SFalse Then
             If TempA!>SFalse And TempA!<=Lof(TreasureFile)/TreasureRecLen Then
                Call Read.Record(TreasureFile,TempA!)
                Out3=TreasureRecord.ShortName
                Out3=Left$(Out3,Len(Parsed.Command1))
                If Out3=Parsed.Command1 Then
                   TempC=TempC+1
                   If Parse.Temp=False Or TempC=Parse.Temp Then
                      Out3=TreasureRecord.TreasureName
                      Out3=Rtrim$(Out3)
                      Temp7!=TempA!
                      Temp6=MessWorkRecord6.Charges
                      Exit Do
                   Endif
                Endif
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp5!=Temp6!
       Loop
    Endif
 Endif
ErrorRsm14:
 Exit Sub
ErrorTrp14:
 Resume ErrorRsm14
End Sub

' check room for object
Sub Check.Room.Items2
 On Local Error Goto ErrorTrp14a
 Temp6=False
 Temp7!=SFalse
 TempC=False
 If Parsed.Command1<>Nul Then
    Temp5!=RoomRecord.First
    If Temp5! Then
       Do While Lost.Carrier=False
          Call Read.Record(RoomInvFile,Temp5!)
          If MessWorkRecord6.Room=SFalse Then
             Exit Do
          Endif
          Temp6!=MessWorkRecord6.Next
          TempA!=MessWorkRecord6.Index
          If TempA!<SFalse Then
             VarA!=Abs(TempA!)
             If VarA!>SFalse And VarA!<=Lof(ObjectFile)/ObjectRecLen Then
                Call Read.Record(ObjectFile,VarA!)
                Out3=Rtrim$(ObjectRecord.ShortName)
                If Out3=Parsed.Command1 Then
                   TempC=TempC+1
                   If Parse.Temp2=False Or TempC=Parse.Temp2 Then
                      Out3=ObjectRecord.ObjectName
                      Out3=Rtrim$(Out3)
                      Temp7!=TempA!
                      Temp6=MessWorkRecord6.Charges
                      Exit Do
                   Endif
                Endif
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp5!=Temp6!
       Loop
    Endif
 Endif
ErrorRsm14a:
 Exit Sub
ErrorTrp14a:
 Resume ErrorRsm14a
End Sub

' check room for treasure
Sub Check.Room.Items3
 On Local Error Goto ErrorTrp14x
 Temp6=False
 Temp7!=SFalse
 TempC=False
 If Parsed.Command1<>Nul Then
    Temp5!=RoomRecord.First
    If Temp5! Then
       Do While Lost.Carrier=False
          Call Read.Record(RoomInvFile,Temp5!)
          If MessWorkRecord6.Room=SFalse Then
             Exit Do
          Endif
          Temp6!=MessWorkRecord6.Next
          TempA!=MessWorkRecord6.Index
          If TempA!>SFalse Then
             Call Read.Record(TreasureFile,TempA!)
             Out3=TreasureRecord.ShortName
             Out3=Left$(Out3,Len(Parsed.Command1))
             If Out3=Parsed.Command1 Then
                TempC=TempC+1
                If Parse.Temp=False Or TempC=Parse.Temp Then
                   Out3=TreasureRecord.TreasureName
                   Out3=Rtrim$(Out3)
                   Temp7!=TempA!
                   Temp6=MessWorkRecord6.Charges
                   Exit Do
                Endif
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp5!=Temp6!
       Loop
    Endif
 Endif
ErrorRsm14x:
 Exit Sub
ErrorTrp14x:
 Resume ErrorRsm14x
End Sub

' check user.index for object
Sub Check.Inventory.Objects
 On Local Error Goto ErrorTrp18
 Temp6=False
 Temp7!=SFalse
 TempC=False
 If Parsed.Command1<>Nul Then
    For Temp5!=1! To Lof(MessWorkFile6)/MessWorkRecLen6
       Call Read.Record(MessWorkFile6,Temp5!)
       If MessWorkRecord6.User=User.Index Then
          VarQ!=MessWorkRecord6.Index
          If VarQ!<SFalse Then
             VarQ!=Abs(VarQ!)
             If VarQ!>SFalse And VarQ!<=Lof(ObjectFile)/ObjectRecLen Then
                Call Read.Record(ObjectFile,VarQ!)
                Out3=ObjectRecord.ShortName
                Out3=Left$(Out3,Len(Parsed.Command1))
                If Out3=Parsed.Command1 Then
                   TempC=TempC+1
                   If Parse.Temp=False Or TempC=Parse.Temp Then
                      Out3=ObjectRecord.ObjectName
                      Out3=Rtrim$(Out3)
                      Temp7!=VarQ!
                      Temp6=MessWorkRecord6.Charges
                      Exit For
                   Endif
                Endif
             Endif
          Endif
       Endif
    Next
 Endif
ErrorRsm18:
 Exit Sub
ErrorTrp18:
 Resume ErrorRsm18
End Sub

' check user.index for treasure
Sub Check.Inventory.Treasure
 On Local Error Goto ErrorTrp17a
 Temp6=False
 Temp7!=SFalse
 TempC=False
 If Parsed.Command1<>Nul Then
    For Temp5!=1! To Lof(MessWorkFile6)/MessWorkRecLen6
       Call Read.Record(MessWorkFile6,Temp5!)
       If MessWorkRecord6.User=User.Index Then
          VarQ!=MessWorkRecord6.Index
          If VarQ!>SFalse And VarQ!<=Lof(TreasureFile)/TreasureRecLen Then
             Call Read.Record(TreasureFile,VarQ!)
             Out3=TreasureRecord.ShortName
             Out3=Left$(Out3,Len(Parsed.Command1))
             If Out3=Parsed.Command1 Then
                TempC=TempC+1
                If Parse.Temp=False Or TempC=Parse.Temp Then
                   Out3=TreasureRecord.TreasureName
                   Out3=Rtrim$(Out3)
                   Temp7!=VarQ!
                   Temp6=MessWorkRecord6.Charges
                   Exit For
                Endif
             Endif
          Endif
       Endif
    Next
 Endif
ErrorRsm17a:
 Exit Sub
ErrorTrp17a:
 Resume ErrorRsm17a
End Sub

' check user.index for object/treasure
Sub Check.User.Items
 On Local Error Goto ErrorTrp17
 Temp6=False
 Temp7!=SFalse
 TempC=False
 If Parsed.Command1<>Nul Then
    For Temp5!=1! To Lof(MessWorkFile6)/MessWorkRecLen6
       Call Read.Record(MessWorkFile6,Temp5!)
       If MessWorkRecord6.User=User.Index Then
          VarQ!=MessWorkRecord6.Index
          If VarQ!<SFalse Then
             VarA!=Abs(VarQ!)
             If VarA!>SFalse And VarA!<=Lof(ObjectFile)/ObjectRecLen Then
                Call Read.Record(ObjectFile,VarA!)
                Out3=ObjectRecord.ShortName
                Out3=Left$(Out3,Len(Parsed.Command1))
                If Out3=Parsed.Command1 Then
                   TempC=TempC+1
                   If Parse.Temp=False Or TempC=Parse.Temp Then
                      Out3=ObjectRecord.ObjectName
                      Out3=Rtrim$(Out3)
                      Temp7!=VarQ!
                      Temp6=MessWorkRecord6.Charges
                      Exit For
                   Endif
                Endif
             Endif
          Endif
          If VarQ!>SFalse Then
             If VarQ!>SFalse And VarQ!<=Lof(TreasureFile)/TreasureRecLen Then
                Call Read.Record(TreasureFile,VarQ!)
                Out3=TreasureRecord.ShortName
                Out3=Left$(Out3,Len(Parsed.Command1))
                If Out3=Parsed.Command1 Then
                   TempC=TempC+1
                   If Parse.Temp=False Or TempC=Parse.Temp Then
                      Out3=TreasureRecord.TreasureName
                      Out3=Rtrim$(Out3)
                      Temp7!=VarQ!
                      Temp6=MessWorkRecord6.Charges
                      Exit For
                   Endif
                Endif
             Endif
          Endif
       Endif
    Next
 Endif
ErrorRsm17:
 Exit Sub
ErrorTrp17:
 Resume ErrorRsm17
End Sub

' check user tempb! for object/treasure
Sub Search.User.Inventory
 On Local Error Goto ErrorTrp19
 Temp6=False
 Temp7!=SFalse
 TempC=False
 If Parsed.Command1<>Nul Then
    For Temp5!=1! To Lof(MessWorkFile6)/MessWorkRecLen6
       Call Read.Record(MessWorkFile6,Temp5!)
       If MessWorkRecord6.User=TempB! Then
          VarQ!=MessWorkRecord6.Index
          If VarQ!<SFalse Then
             VarA!=Abs(VarQ!)
             If VarA!>SFalse And VarA!<=Lof(ObjectFile)/ObjectRecLen Then
                Call Read.Record(ObjectFile,VarA!)
                Out3=ObjectRecord.ShortName
                Out3=Left$(Out3,Len(Parsed.Command1))
                If Out3=Parsed.Command1 Then
                   TempC=TempC+1
                   If Parse.Temp=False Or TempC=Parse.Temp Then
                      Out3=ObjectRecord.ObjectName
                      Out3=Rtrim$(Out3)
                      Temp7!=VarQ!
                      Temp6=MessWorkRecord6.Charges
                      Exit For
                   Endif
                Endif
             Endif
          Endif
          If VarQ!>SFalse And VarQ!<=Lof(TreasureFile)/TreasureRecLen Then
             Call Read.Record(TreasureFile,VarQ!)
             Out3=TreasureRecord.ShortName
             Out3=Left$(Out3,Len(Parsed.Command1))
             If Out3=Parsed.Command1 Then
                TempC=TempC+1
                If Parse.Temp=False Or TempC=Parse.Temp Then
                   Out3=TreasureRecord.TreasureName
                   Out3=Rtrim$(Out3)
                   Temp7!=VarQ!
                   Temp6=MessWorkRecord6.Charges
                   Exit For
                Endif
             Endif
          Endif
       Endif
    Next
 Endif
ErrorRsm19:
 Exit Sub
ErrorTrp19:
 Resume ErrorRsm19
End Sub

' check offline user linked list inventory for object/treasure
Sub Search.User.Inventory2
 On Local Error Goto ErrorTrp19x
 Temp6=False
 Temp7!=SFalse
 TempC=False
 TempA!=SFalse
 If Parsed.Command1<>Nul Then
    Temp4!=UserRecord2.First
    If Temp4! Then
       Do While Lost.Carrier=False
          Call Read.Record(UserInvFile,Temp4!)
          Temp6!=MessWorkRecord6.Next
          VarQ!=MessWorkRecord6.Index
          If VarQ!<SFalse Then
             VarA!=Abs(VarQ!)
             If VarA!>SFalse And VarA!<=Lof(ObjectFile)/ObjectRecLen Then
                Call Read.Record(ObjectFile,VarA!)
                Out3=ObjectRecord.ShortName
                Out3=Left$(Out3,Len(Parsed.Command1))
                If Out3=Parsed.Command1 Then
                   TempC=TempC+1
                   If Parse.Temp=False Or TempC=Parse.Temp Then
                      Out3=ObjectRecord.ObjectName
                      Out3=Rtrim$(Out3)
                      Temp7!=VarQ!
                      Temp6=MessWorkRecord6.Charges
                      Exit Do
                   Endif
                Endif
             Endif
          Endif
          If VarQ!>SFalse And VarQ!<=Lof(TreasureFile)/TreasureRecLen Then
             Call Read.Record(TreasureFile,VarQ!)
             Out3=TreasureRecord.ShortName
             Out3=Left$(Out3,Len(Parsed.Command1))
             If Out3=Parsed.Command1 Then
                TempC=TempC+1
                If Parse.Temp=False Or TempC=Parse.Temp Then
                   Out3=TreasureRecord.TreasureName
                   Out3=Rtrim$(Out3)
                   Temp7!=VarQ!
                   Temp6=MessWorkRecord6.Charges
                   Exit Do
                Endif
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp4!=Temp6!
       Loop
    Endif
 Endif
ErrorRsm19x:
 Exit Sub
ErrorTrp19x:
 Resume ErrorRsm19x
End Sub

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

Sub In.Room(Var)
 On Local Error Goto ErrorTrp2
 Var1$=","+Rtrim$(Room.Array(Var))+","
 Var2$=","+Mid$(Str$(Room),2)+","
 If Instr(Var1$,Var2$) Then
    TempA=True
 Else
    TempA=False
 Endif
ErrorRsm2:
 Exit Sub
ErrorTrp2:
 Resume ErrorRsm2
End Sub

Sub Player.Died
 On Local Error Goto ErrorTrap25
 Gosub Get.Config1
 If Vehicle1 Then
    Call Remove.Vehicle
    Vehicle1=SFalse
    Vehicle2=False
    Vehicle3=SFalse
 Endif
 UserRecord.Poison=False
 Strng=Message1
 If Len(Strng) Then
    Call IO.O
 Endif
 UserRecord.TimesDied=UserRecord.TimesDied+1#
 Call Write.Record(UserFile,User.Index)
 If Normal.User=False Then
    Strng="You were resurrected!"
    Call IO.O
    Gosub Died.Times
    If GuestLogin Then
       Next.Room=GuestRecord.GuestRoomResurrect
    Else
       Next.Room=Int(Val(Config3(24))+.5)
    Endif
    Action.Recurse=0
    Call Enter.Room
    Exit Sub
 Endif
 Temp4=UserRecord.Stats(5)
 If Temp4>1 Then
    UserRecord.Stats(5)=Temp4-1
    Out2=Stat(5)
    Out2=Rtrim$(Out2)
    Out2=Lcase$(Out2)
    Strng="lost one "+Out2+" point"
    Call Update.DayFile(Strng,False,2)
    Strng="You "+Lcase$(Strng)+"!"
    Call IO.O
 Endif
 Temp4=UserRecord.Stats(6)
 If Temp4>1 Then
    UserRecord.Stats(6)=Temp4-1
    Out2=Stat(6)
    Out2=Rtrim$(Out2)
    Out2=Lcase$(Out2)
    Strng="lost one "+Out2+" point"
    Call Update.DayFile(Strng,False,2)
    Strng="You "+Lcase$(Strng)+"!"
 Endif
 If Len(option1$) Then
    Out2=option1$
    Call Equate(Temp#)
 Else
    Temp#=Rnd>.5
 Endif
 If Temp# Then
    If Len(option2$) Then
       Out2=option2$
       Call Equate(Temp#)
    Else
       Temp#=Int(Rnd*4+1)
    Endif
    Temp=Int(Temp#)
    If Temp>=1 And Temp<=7 Then
       Temp4=UserRecord.Stats(Temp2)
       If Temp4>1 Then
          UserRecord.Stats(Temp2)=Temp4-1
          Out2=Stat(Temp2)
          Out2=Rtrim$(Out2)
          Out2=Lcase$(Out2)
          Strng="lost one "+Out2+" point"
          Call Update.DayFile(Strng,False,2)
          Strng="You "+Lcase$(Strng)+"!"
       Endif
    Endif
 Endif
 UserRecord.Gold=Config2(32)
 Gosub Died.Times
 UserRecord.Poison=False
 UserRecord.First=SFalse
 UserRecord.Last=SFalse
 If Config2(108) Then
    Call Drop.All.UserContainers
    Weight=False
    Call Clear.UserWeapons
    Call Drop.All.UserItems
    Call Clear.UserInv
 Endif
 UserRecord.Fatigue=False
 UserRecord.Vitality=False
 UserRecord.Magic=False
 UserRecord.Psionic=False
 If GuestLogin Then
    Room=GuestRecord.GuestRoomResurrect
    Next.Room=GuestRecord.GuestRoomResurrect
 Else
    Room=Int(Val(Config3(24))+.5)
    Next.Room=Int(Val(Config3(24))+.5)
 Endif
 Out2="Has just died!"
 If Node>False Then
    Call Send.Mess(4,SFalse,SFalse,Out2)
 Endif
 If Config2(63) Then
    Out2=Config3(45)
    Call Equate(Temp#)
 Else
    Temp#=(Int(Rnd*10+10)+UserRecord.Stats(5)/2)>20
 Endif
 If Temp#=DFalse Then
    Strng="Constitution roll failed!"
    Call IO.O
    Strng=Nul
    Temp1=UserRecord.Level
    If Temp1>=1 Then
       Temp1=Int(Temp1/2+.5)
    Else
       Temp1=False
    Endif
    Select Case Temp1
    Case 1 To 10
       Strng="lost "+Rtrim$(Numeral(Temp1))
    Case Is>10
       Strng="lost"+Str$(Temp1)
    End Select
    Select Case Temp1
    Case 1
       Strng=Strng+" level"
    Case Is>1
       Strng=Strng+" levels"
    End Select
    If Len(Strng) Then
       Call Update.DayFile(Strng,False,2)
       Strng="You "+Lcase$(Strng)+"!"
       Call IO.O
    Endif
    UserRecord.Level=Int(UserRecord.Level/2)
    Strng="You were not resurrected!"
    Call IO.O
    If Config2(39) Then
       Call Hang.Up(9)
    Endif
 Else
    UserRecord.Level=UserRecord.Level-1
    Strng="lost one level"
    Call Update.DayFile(Strng,False,2)
    Strng="You "+Lcase$(Strng)+"!"
    Call IO.O
    Strng="You were resurrected!"
    Call IO.O
    If UserRecord.Stats(5)<=1 Then
       Strng="Except your constitution failed!"
       Call IO.O
       UserRecord.Level=1
    Endif
 Endif
 Action.Recurse=0
 Call Enter.Room
 Call Zero.Stats
 Exit Sub
' reward death
Died.Times:
 If UserRecord.TimesDied > 0# Then
    If (UserRecord.TimesDied MOD Option1#) = 0# Then
       Call Amount(UserRecord.TimesDied,Var$)
       Call Amount(Option2#,Var2$)
       Strng="For dying"+Var$+" times you earn"+Var2$+" gold!"
       Call IO.O
       UserRecord.Gold=UserRecord.Gold+Option2#
       Strng="was rewarded for dying"
       Call Update.DayFile(Strng,False,2)
    Endif
 Endif
 Return
Get.Config1:
 Option1#=10#
 Option2#=1000#
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[TRAIN]" Then
       Do
          VarX=VarX+1
          If VarX>Options.Lines Then
             Return
          Endif
          Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
          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)))
             Select Case Lcase$(Var2$)
             Case "lose.point.equation"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option1$=Mid$(Var3$,2)
                      option1$=Left$(option1$,Len(option1$)-1)
                   Endif
                Endif
             Case "lose.point"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option2$=Mid$(Var3$,2)
                      option2$=Left$(option2$,Len(option2$)-1)
                   Endif
                Endif
             Case "times.died.counter"
                If Int(Val(Var3$)+.5)>0# Then
                   Option1#=Int(Val(Var3$)+.5)
                Endif
             Case "times.died.reward"
                If Int(Val(Var3$)+.5)>0# Then
                   Option2#=Int(Val(Var3$)+.5)
                Endif
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
ErrorResume25:
 Exit Sub
ErrorTrap25:
 Resume ErrorResume25
End Sub

Sub Remove.Vehicle
 On Local Error Goto Err.Trap15a
 Call Read.Record(RoomInvFile,Vehicle1)
 Call Read.Record(TreasureFile,Vehicle3)
 If MessWorkRecord6.User=User.Index Then
    MessWorkRecord6.User=SFalse
    If TreasureRecord.Occupants>False Then
       If MessWorkRecord6.Temp(1)>SFalse Then
          MessWorkRecord6.User=MessWorkRecord6.Temp(1)
          For Var2=1 To 3
             MessWorkRecord6.Temp(Var2)=MessWorkRecord6.Temp(Var2+1)
          Next
          MessWorkRecord6.Temp(4)=SFalse
       Endif
    Endif
 Else
    For Var=1 To 4
       If MessWorkRecord6.Temp(Var)=User.Index Then
          For Var2=Var To 3
             MessWorkRecord6.Temp(Var2)=MessWorkRecord6.Temp(Var2+1)
          Next
          MessWorkRecord6.Temp(4)=SFalse
          Exit For
       Endif
    Next
 Endif
 Call Write.Record(RoomInvFile,Vehicle1)
Err.Resume15a:
 Exit Sub
Err.Trap15a:
 Resume Err.Resume15a
End Sub

Sub Zero.Stats
 On Local Error Goto ErrorTrap26
 UserRecord.Experience=False
 If Config2(93)=False Then
    Call Experience(Temp#)
    UserRecord.Experience=Temp#
 Endif
 Call New.Stats
 Call Put.User.Record
 UserRecord.Flags=UserRecord.Flags And Not Wished
 UserRecord.Flags=UserRecord.Flags And Not Rerolled
 UserRecord.Flags=UserRecord.Flags And Not Alignmented
 Call Write.Record(UserFile,User.Index)
ErrorResume26:
 Exit Sub
ErrorTrap26:
 Resume ErrorResume26
End Sub

Sub Drop.All.UserItems
 On Local Error Goto ErrorTrap25a
 For Temp1!=1! To Lof(MessWorkFile6)/MessWorkRecLen6
    Call Read.Record(MessWorkFile6,Temp1!)
    If MessWorkRecord6.User=User.Index Then
       Var1!=MessWorkRecord6.Index
       Var2=MessWorkRecord6.Charges
       Call Drop.Inventory(Var1!,Var2)
       MessWorkRecord6.User=SFalse
       MessWorkRecord6.Room=SFalse
       MessWorkRecord6.Index=SFalse
       MessWorkRecord6.Charges=False
       MessWorkRecord6.Plus=False
       MessWorkRecord6.Prev=SFalse
       MessWorkRecord6.Next=SFalse
       Call Write.Record(MessWorkFile6,Temp1!)
    Endif
 Next
ErrorResume25a:
 Exit Sub
ErrorTrap25a:
 Resume ErrorResume25a
End Sub

Sub Drop.All.UserContainers
 On Local Error Goto ErrorTrap25x
 Temp3!=UserRecord.First2 ' containers
 If Temp3! Then
    Do
       Call Read.Record(ContainerFile,Temp3!)
       VarQ!=ContainerRecord.Next
       ' drop container
       Call Delete.User.Container(Temp3!)
       Call Read.Record(ContainerFile,Temp3!)
       ContainerRecord.RoomNumber=Room
       ContainerRecord.UserNumber=SFalse
       ContainerRecord.InvisibleContainer=False
       Call Add.Room.Container(Temp3!)
       If VarQ!=SFalse Then
          Exit Do
       Endif
       Temp3!=VarQ!
    Loop
 Endif
ErrorResume25x:
 Exit Sub
ErrorTrap25x:
 Resume ErrorResume25x
End Sub

' prepares new room for entry.
Sub Enter.Room
 On Local Error Goto Err.Trap11
 Call Check.Room.Number(Next.Room)
 Call Store.Perm.Monsters
 Call Monsters.Teleport
 Call Clean.Room.Node(Next.Room)
 If Ignore.Vehicle=False Then
    Call Move.Vehicle
 Endif
 Call New.Rates
 Call More.Room.Actions
 Call Enter.Room.Actions
 Call Update.Mess(4)
 Room.Rust.Rate=False
 Room.Steal.Rate=False
 ' clear offer nodes
 VarX2=Node+1
 Call Read.Message.Record(MessWorkFile1,VarX2)
 MessWorkRecord1.OfferTime=False
 Call Write.Message.Record(MessWorkFile1,VarX2)
 Temp1=MessWorkRecord1.ToNode
 If Temp1>False Then
    Call Read.Message.Record(MessWorkFile1,Temp1+1)
    MessWorkRecord1.OfferTime=False
    Call Write.Message.Record(MessWorkFile1,Temp1+1)
 Endif
Err.Resume11:
 Exit Sub
Err.Trap11:
 Resume Err.Resume11
End Sub

Sub Clear.UserInv
 On Local Error Goto ErrorTrap30a
 For Var4!=1! To Lof(UserInvFile)/MessWorkRecLen6
    Call Read.Record(UserInvFile,Var4!)
    If MessWorkRecord6.User=User.Index Then
       MessWorkRecord6.User=SFalse
       MessWorkRecord6.Room=SFalse
       MessWorkRecord6.Index=SFalse
       MessWorkRecord6.Charges=False
       MessWorkRecord6.Plus=False
       MessWorkRecord6.Prev=SFalse
       MessWorkRecord6.Next=SFalse
       Call Write.Record(UserInvFile,Var4!)
    Endif
 Next
ErrorResume30a:
 Exit Sub
ErrorTrap30a:
 Resume ErrorResume30a
End Sub

Sub Clear.UserWeapons
 On Local Error Goto ErrorTrap30b
 For Temp6=1 To 10
    If UserRecord.Weapon(Temp6).Index Then
       Var1!=UserRecord.Weapon(Temp6).Index
       Var2=UserRecord.Weapon(Temp6).Charges
       UserRecord.Weapon(Temp6).Index=SFalse
       UserRecord.Weapon(Temp6).Plus=False
       Call Read.Record(TreasureFile,Var1!)
       Call Add.Inventory(Var1!,Var2)
    Endif
 Next
 Call Write.Record(UserFile,User.Index)
ErrorResume30b:
 Exit Sub
ErrorTrap30b:
 Resume ErrorResume30b
End Sub

Sub Safe.Room2
 On Local Error Goto ErrorTrp1x
 TempA=False
 If Next.Room=1 Then
    TempA=True
 Else
    Var1$=","+Rtrim$(Room.Array(11))+","
    Var2$=","+Mid$(Str$(Next.Room),2)+","
    If Instr(Var1$,Var2$) Then
       TempA=True
    Else
       If GuestLogin Then
          If Next.Room=GuestRecord.GuestRoomResurrect Then
             TempA=True
          Endif
       Endif
    Endif
 Endif
ErrorRsm1x:
 Exit Sub
ErrorTrp1x:
 Resume ErrorRsm1x
End Sub

Sub Monsters.Teleport
 On Local Error Goto Err.Trap13
 Gosub Get.Config2
 If Option1=0 Then
    If UserRecord.ClassType>=Lady Then
       Exit Sub
    Endif
 Endif
 If Option2=0 Then
    Call Safe.Room2
    If TempA Then
       Exit Sub
    Endif
 Endif
 If Teleported Then
    Out3=" teleports with you!"
 Else
    Out3=" follows you!"
 Endif
 VarQ1=False
 VarQ2=False
 VarZ1=False
 VarZ2=False
 For Var1!=1! To Lof(MessWorkFile3)/MessWorkRecLen3
    Call Read.Record(MessWorkFile3,Var1!)
    If MessWorkRecord3.Room=Room Then
       TempA=False
       If MessWorkRecord3.Monster.Follow Then
          If Teleported Then
             If Rnd<(MessWorkRecord3.Monster.TeleportPercent/100) Then
                TempA=True
             Endif
          Else
             If Rnd<(MessWorkRecord3.Monster.FollowPercent/100) Then
                TempA=True
             Endif
          Endif
          If MessWorkRecord3.Monster.Permanent Then
             TempA=False
          Endif
          If MessWorkRecord3.Monster.RemainsInRoom=False Then
             TempA=False
          Endif
          If MessWorkRecord3.IsAutomaton Then
             TempA=False
          Endif
          If TempA Then
             VarY=False
             If Teleported Or Option3 Then
                ' check left ring
                Var2!=UserRecord.Weapon(4).Index
                If Var2! Then
                   Call Read.Record(TreasureFile,Var2!)
                   If TreasureRecord.RingType=9 Then ' anti-teleport
                      Var3=UserRecord.Weapon(4).Charges
                      If Var3>False Then
                         VarQ1=VarQ1+1
                         VarY=True
                         Var3=Var3-1
                         UserRecord.Weapon(4).Charges=Var3
                         If Var3<=False Then
                            VarZ1=True
                            UserRecord.Weapon(4).Index=SFalse
                            UserRecord.Weapon(4).Charges=False
                            UserRecord.Weapon(4).Plus=False
                         Endif
                      Endif
                   Endif
                Endif
                If VarY=False Then
                   ' check right ring
                   Var2!=UserRecord.Weapon(9).Index
                   If Var2! Then
                      Call Read.Record(TreasureFile,Var2!)
                      If TreasureRecord.RingType=9 Then ' anti-teleport
                         Var3=UserRecord.Weapon(9).Charges
                         If Var3>False Then
                            VarQ2=VarQ2+1
                            VarY=True
                            Var3=Var3-1
                            UserRecord.Weapon(9).Charges=Var3
                            If Var3<=False Then
                               VarZ2=True
                               UserRecord.Weapon(9).Index=SFalse
                               UserRecord.Weapon(9).Charges=False
                               UserRecord.Weapon(9).Plus=False
                            Endif
                         Endif
                      Endif
                   Endif
                Endif
             Endif
             ' monster moves with player
             If VarY=False Then
                MessWorkRecord3.Room=Next.Room
                Call Write.Record(MessWorkFile3,Var1!)
                If MessWorkRecord3.Monster.Invisible=False Then
                   Out2=MessWorkRecord3.Monster.MonsterName
                   Out2=Lcase$(Rtrim$(Out2))
                   Strng="The "+Out2+Out3
                   Call IO.O
                Endif
             Endif
          Endif
       Endif
    Endif
 Next
 Teleported=False
 If VarQ1 Then
    If VarQ1=1 Then
       Strng="Your left ring absorbs a hit"
    Else
       Strng="Your left ring absorbs "+Form$(Cdbl(VarQ1))+" hits"
    Endif
    If VarZ1 Then
       Strng=Strng+" and disintegrated"
    Endif
    Strng=Strng+"!"
    Call IO.O
 Endif
 If VarQ2 Then
    If VarQ2=1 Then
       Strng="Your right ring absorbs a hit"
    Else
       Strng="Your right ring absorbs "+Form$(Cdbl(VarQ2))+" hits"
    Endif
    If VarZ2 Then
       Strng=Strng+" and disintegrated"
    Endif
    Strng=Strng+"!"
    Call IO.O
 Endif
 Exit Sub
Get.Config2:
 Option1=0
 Option2=0
 Option3=0
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[TRAIN]" Then
       Do
          VarX=VarX+1
          If VarX>Options.Lines Then
             Return
          Endif
          Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
          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)))
             Select Case Lcase$(Var2$)
             Case "override.classtype"
                Select Case Lcase$(Var3$)
                Case "-1", "true", "on"
                   Option1=-1
                End Select
             Case "override.saferoom"
                Select Case Lcase$(Var3$)
                Case "-1", "true", "on"
                   Option2=-1
                End Select
             Case "also.follow"
                Select Case Lcase$(Var3$)
                Case "-1", "true", "on"
                   Option3=-1
                End Select
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
Err.Resume13:
 Exit Sub
Err.Trap13:
 Resume Err.Resume13
End Sub

Sub Put.User.Record
 On Local Error Goto ErrorTrp54
 If User.Index=SFalse Then
    Exit Sub
 Endif
 Var$=UserRecord.CodeName
 Call Valid.Name(Var$)
 If TempA=False Then
    Exit Sub
 Endif
 If Rtrim$(Var$)=Nul Then
    Exit Sub
 Endif
 For Temp7!=1! To Lof(UserInvFile)/MessWorkRecLen6
    Call Read.Record(UserInvFile,Temp7!)
    If MessWorkRecord6.User=User.Index Then
       MessWorkRecord6.User=SFalse
       MessWorkRecord6.Room=SFalse
       MessWorkRecord6.Index=SFalse
       MessWorkRecord6.Charges=False
       MessWorkRecord6.Plus=False
       MessWorkRecord6.Prev=SFalse
       MessWorkRecord6.Next=SFalse
       Call Write.Record(UserInvFile,Temp7!)
    Endif
 Next
 UserRecord.First=SFalse
 UserRecord.Last=SFalse
 Call Write.Record(UserFile,User.Index)
 For Temp7!=1! To Lof(MessWorkFile6)/MessWorkRecLen6
    Call Read.Record(MessWorkFile6,Temp7!)
    If MessWorkRecord6.User=User.Index Then
       Temp6!=Lof(UserInvFile)/MessWorkRecLen6+1!
       Call Add.List.Node3(Temp6!)
    Endif
 Next
 Call Write.User.Record
ErrorRsm54:
 Exit Sub
ErrorTrp54:
 Resume ErrorRsm54
End Sub

Sub Store.Perm.Monsters
 On Local Error Goto Err.Trap12
 For Temp5!=1! To Lof(MessWorkFile3)/MessWorkRecLen3
    Call Read.Record(MessWorkFile3,Temp5!)
    If MessWorkRecord3.Room=Room Then
       If MessWorkRecord3.Monster.Permanent=True Then
          Temp2!=MessWorkRecord3.Index
          Call Read.Record(MonsterFile,Temp2!)
          MonsterRecord.Level=MessWorkRecord3.Monster.Level
          MonsterRecord.Hits=MessWorkRecord3.Monster.Hits
          Call Write.Record(MonsterFile,Temp2!)
       Endif
    Endif
 Next
Err.Resume12:
 Exit Sub
Err.Trap12:
 Resume Err.Resume12
End Sub

Sub Enter.Room.Actions
 On Local Error Goto Err.Trap16
 Var!=RoomRecord.Action
 If Var!>SFalse And Var!<=Lof(ActionFile)/ActionRecLen Then
    Call Read.Record(ActionFile,Var!)
    VarQ=ActionRecord.PoisonPercent
    If VarQ<0 Then
       VarQ=Abs(VarQ)
       If Int(Rnd*100+1)<=VarQ Then
          If UserRecord.Poison Then
             UserRecord.Poison=0
             Strng="As you enter the room you are curepoisoned!"
             Call IO.O
          Endif
       Endif
    Endif
 Endif
 Call Safe.Room
 If TempA Then
    Exit Sub
 Endif
 Var!=RoomRecord.Action
 If Var!>SFalse And Var!<=Lof(ActionFile)/ActionRecLen Then
    Call Read.Record(ActionFile,Var!)
    VarQ=ActionRecord.PoisonPercent
    If VarQ>0 Then
       If Int(Rnd*100+1)<=VarQ Then
          If UserRecord.Poison=0 Then
             UserRecord.Poison=-1
             Strng="As you enter the room you are poisoned!"
             Call IO.O
          Endif
       Endif
    Endif
    VarQ=ActionRecord.WishPercent
    If VarQ<0 Then
       VarQ=Abs(VarQ)
       If Int(Rnd*100+1)<=VarQ Then
          If UserRecord.WishsLeft>0 Then
             UserRecord.WishsLeft=UserRecord.WishsLeft-1
             Strng="As you enter the room you lose a wish!"
             Call IO.O
          Endif
       Endif
    Else
       If VarQ>0 Then
          If Int(Rnd*100+1)<=VarQ Then
             If UserRecord.WishsLeft>=0 And UserRecord.WishsLeft<MaxInt Then
                UserRecord.WishsLeft=UserRecord.WishsLeft+1
                Strng="As you enter the room you are granted a wish!"
                Call IO.O
             Endif
          Endif
       Endif
    Endif
    If ActionRecord.SpellTrigger=SFalse Then
       Var2=False
       For Var3=1 To 3
          If ActionRecord.AttackMonster(Var3)<>SFalse Then
             Var2=True
             Exit For
          Endif
          If ActionRecord.MonsterTalk(Var3)<>SFalse Then
             Var2=True
             Exit For
          Endif
          If ActionRecord.MonsterTrigger(Var3)<>SFalse Then
             Var2=True
             Exit For
          Endif
       Next
       If Var2=False Then
          If Normal.User=False Then
             Out3="As you enter room"+Str$(Next.Room)+","
          Else
             Out3="As you enter the room,"
          Endif
          Out4="You are hit for"
          Call Actions(Var!)
       Endif
    Endif
 Endif
Err.Resume16:
 Exit Sub
Err.Trap16:
 Resume Err.Resume16
End Sub

Sub More.Room.Actions
 On Local Error Goto Err.Trap17x
 Call Safe.Room
 If TempA Then
    Exit Sub
 Endif
 If Vehicle1 Then
    Exit Sub
 Endif
 Var5!=RoomRecord.First
 If Var5! Then
    Do While Lost.Carrier=False
       Call Read.Record(RoomInvFile,Var5!)
       If MessWorkRecord6.Room=SFalse Then
          Exit Do
       Endif
       Var6!=MessWorkRecord6.Next
       Var2!=MessWorkRecord6.Index
       If Var2!>SFalse And Var2!<=Lof(TreasureFile)/TreasureRecLen Then
          Call Read.Record(TreasureFile,Var2!)
          If (TreasureRecord.Edible And 1)=1 Then ' edible
             If (TreasureRecord.Edible And 2)=2 Then ' slippery
                Out3=TreasureRecord.TreasureName
                Out3=Rtrim$(Out3)
                Out3=Lcase$(Out3)
                Strng="As you enter the room,"
                Call IO.O
                Strng="You slip on "+Out3+"!"
                Call IO.O
                Select Case Rnd
                Case Is>.75
                   Strng="You broke your left ankle!"
                Case Is>.5
                   Strng="You sprained your left ankle!"
                Case Else
                   Strng="You hurt your left ankle!"
                End Select
                Call IO.O
                Var=TreasureRecord.Plus
                If Var>False Then
                   Strng="You are hit for"
                   Out3="a slippery item"
                   Call Hit.Player(Var)
                Endif
                Exit Do
             Endif
          Endif
       Endif
       If Var6!=SFalse Then
          Exit Do
       Endif
       Var5!=Var6!
    Loop
 Endif
Err.Resume17x:
 Exit Sub
Err.Trap17x:
 Resume Err.Resume17x
End Sub

Sub Actions(VarZ!)
 On Local Error Goto ErrorTrp58
 Gosub Get.Config4
 ' check actions in safe room
 Call Safe.Room
 If TempA Then
    Exit Sub
 Endif
 ' check actions in sanctuary
 If Room=Int(Val(Config3(24))+.5) Then
    Exit Sub
 Endif
 ' check action reccord number
 If VarZ!<=SFalse Or VarZ!>Lof(ActionFile)/ActionRecLen Then
    Exit Sub
 Endif
 ' read action record
 Call Read.Record(ActionFile,VarZ!)
 ' check inventory action
 Graphics.Off=False
 Out2=Nul
 Var1=ActionRecord.Inventory
 If Var1 Then
    Temp4=False
    VarX=False
    Var2!=UserRecord.Weapon(4).Index
    If Var2! Then
       Call Read.Record(TreasureFile,Var2!)
       If TreasureRecord.RingType=7 Then
          VarX=True
          Call Get.Ring.Hits(True,7)
       Endif
    Endif
    If VarX=False Then
       Var2!=UserRecord.Weapon(9).Index
       If Var2! Then
          Call Read.Record(TreasureFile,Var2!)
          If TreasureRecord.RingType=7 Then
             VarX=True
             Call Get.Ring.Hits(False,7)
          Endif
       Endif
    Endif
    If VarX=False Then
       Temp5=False
       For Temp2!=1! To Lof(MessWorkFile6)/MessWorkRecLen6
          Call Read.Record(MessWorkFile6,Temp2!)
          If MessWorkRecord6.User=User.Index Then
             VarQ!=MessWorkRecord6.Index
             If VarQ!>SFalse And VarQ!<=Lof(TreasureFile)/TreasureRecLen Then
                Call Read.Record(TreasureFile,VarQ!)
                If TreasureRecord.WeaponNumber=Var1 Then
                   If MessWorkRecord6.Charges>False Then
                      Temp4=True
                      If ActionRecord.InvPercent>False Then
                         If Int(Rnd*100+1)>ActionRecord.InvPercent Then
                            Temp4=False
                         Endif
                      Endif
                      If Temp4 Then
                         If ActionRecord.InvNumber>False Then
                            If Temp5>=ActionRecord.InvNumber Then
                               Temp4=False
                            Endif
                         Endif
                         If Temp4 Then
                            Temp5=Temp5+1
                            MessWorkRecord6.Charges=False
                            Call Write.Record(MessWorkFile6,Temp2!)
                         Endif
                      Endif
                   Endif
                Endif
             Endif
          Endif
       Next
       If Temp5 Then
          Strng=Out3
          Call IO.O
          Strng2=Rtrim$(InventoryNames(Var1))
          Select Case Var1
          Case 1
             Strng2=Strng2+" breaks"
          Case 2 To 8
             Strng2=Strng2+"s break"
          End Select
          If ActionRecord.InvPercent Or ActionRecord.InvNumber Then
             If Temp5>=1 And Temp5<=10 Then
                Strng=Rtrim$(Numeral(Temp5))
             Else
                Strng=Mid$(Str$(Temp5),2)
             Endif
             Strng=Strng+" of your "+Strng2+"!"
             Mid$(Strng,1,1)=Ucase$(Mid$(Strng,1,1))
          Else
             Strng="All your "+Strng2+"!"
          Endif
          Call IO.O
       Endif
    Endif
 Endif
 ' check fumble action
 If ActionRecord.Fumble Then
    VarX=False
    Var2!=UserRecord.Weapon(4).Index
    If Var2! Then
       Call Read.Record(TreasureFile,Var2!)
       If TreasureRecord.RingType=8 Then
          VarX=True
          Call Get.Ring.Hits(True,8)
       Endif
    Endif
    If VarX=False Then
       Var2!=UserRecord.Weapon(9).Index
       If Var2! Then
          Call Read.Record(TreasureFile,Var2!)
          If TreasureRecord.RingType=8 Then
             VarX=True
             Call Get.Ring.Hits(False,8)
          Endif
       Endif
    Endif
    If VarX=False Then
       Call Fumble
    Endif
 Endif
 ' verify teleport action exists
 VarQ=False
 For TempQ=1 To 5
    If ActionRecord.Teleport(TempQ)>SFalse Then
       If ActionRecord.Teleport(TempQ)<>Room Then
          VarQ=True
          Exit For
       Endif
    Endif
 Next
 ' check teleport action
 If VarQ Then
    ' check ring activity
    VarX=False
    Var2!=UserRecord.Weapon(4).Index
    If Var2! Then
       Call Read.Record(TreasureFile,Var2!)
       If TreasureRecord.RingType=9 Then
          VarX=True
          Call Get.Ring.Hits(True,9)
       Endif
    Endif
    If VarX=False Then
       Var2!=UserRecord.Weapon(9).Index
       If Var2! Then
          Call Read.Record(TreasureFile,Var2!)
          If TreasureRecord.RingType=9 Then
             VarX=True
             Call Get.Ring.Hits(False,9)
          Endif
       Endif
    Endif
    ' verify teleport percent
    If ActionRecord.TelePercent>False Then
       If Int(Rnd*100+1)>ActionRecord.TelePercent Then
          VarX=True
       Endif
    Endif
    If VarX=False Then
       ' find teleport room number
       VarZ=0
       Do
          ' check indefinite loop
          VarZ=VarZ+1
          If VarZ>1024 Then
             Action.Recurse=Option1
             Exit Do
          Endif
          ' get teleport room number
          VarY=Int(Rnd*5+1)
          If ActionRecord.Teleport(VarY)>SFalse Then
             If ActionRecord.Teleport(VarY)<>Room Then
                Exit Do
             Endif
          Endif
       Loop
       ' check teleport room number
       Action.Recurse=Action.Recurse+1
       If Action.Recurse>Option1 Then
          Strng="Action recurse error."
          Call IO.O
          Strng="You are teleported to a safe room!"
          Call IO.O
          If GuestLogin Then
             Next.Room=GuestRecord.GuestRoomResurrect
          Else
             Next.Room=Int(Val(Config3(24))+.5)
          Endif
          If Next.Room=0! Then
             Next.Room=1!
          Endif
          Call Teleport
          Action.Recurse=0
          Call Enter.Room
          Exit Sub
       Else
          Strng=Out3
          Call IO.O
          Strng="You are teleported elsewhere!"
          If Action.Recurse>0 Then
             Strng=Strng+" (recurse"+Str$(Action.Recurse)+")."
          Endif
          Call IO.O
          Next.Room=ActionRecord.Teleport(VarY)
          Call Teleport
          Call Enter.Room
          Exit Sub
       Endif
    Endif
 Endif
 ' check hits on player from action
 Temp2=ActionRecord.HitPoints
 If Temp2 Then
    Strng=Out3
    Call IO.O
    Strng=Out4
    Prefix2=Nul
    Out3="entering a room"
    Call Hit.Player(Temp2)
 Endif
 Exit Sub
Get.Config4:
 Option1=MaxRoomRecurse
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[TRAIN]" Then
       Do
          VarX=VarX+1
          If VarX>Options.Lines Then
             Return
          Endif
          Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
          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)))
             Select Case Lcase$(Var2$)
             Case "max.room.recurse"
                If Int(Val(Var3$)+.5)>0 And Int(Val(Var3$)+.5)<=8 Then
                   Option1=Int(Val(Var3$)+.5)
                Endif
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
ErrorRsm58:
 Exit Sub
ErrorTrp58:
 Resume ErrorRsm58
End Sub

Sub Write.User.Record
 On Local Error Goto ErrorTrp55
 UserRecord.Room=Room
 UserRecord.SortInv=Sorting
 UserRecord.Hidden=Hidden.Player
 Call Write.Record(UserFile,User.Index)
ErrorRsm55:
 Exit Sub
ErrorTrp55:
 Resume ErrorRsm55
End Sub

Sub Move.Vehicle
 On Local Error Goto Err.Trap15
 If Last.Command.Number=RideVehicle Then
    Var=MessWorkRecord6.Charges
    VarX1!=MessWorkRecord6.Temp(1)
    VarX2!=MessWorkRecord6.Temp(2)
    VarX3!=MessWorkRecord6.Temp(3)
    VarX4!=MessWorkRecord6.Temp(4)
    Call Delete.List.Node(Vehicle1)
    Swap Room,Next.Room
    MessWorkRecord6.Room=Room
    MessWorkRecord6.User=User.Index
    MessWorkRecord6.Index=Vehicle3
    MessWorkRecord6.Plus=False
    MessWorkRecord6.Charges=Var
    MessWorkRecord6.Temp(1)=VarX1!
    MessWorkRecord6.Temp(2)=VarX2!
    MessWorkRecord6.Temp(3)=VarX3!
    MessWorkRecord6.Temp(4)=VarX4!
    Call Add.List.Node(Vehicle1)
    Swap Room,Next.Room
    Last.Command.Number=False
    Call Update.Vehicles
    Exit Sub
 Endif
 If Vehicle1 Then
    Call Pack.Vehicles
 Endif
Err.Resume15:
 Exit Sub
Err.Trap15:
 Resume Err.Resume15
End Sub

' remove user.index vehicle1 from vehicle array.
Sub Pack.Vehicles
 On Local Error Goto ErrorTrap13x2
 Call Read.Record(RoomInvFile,Vehicle1)
 Call Read.Record(TreasureFile,Vehicle3)
 Var3=False ' owner changed
 If MessWorkRecord6.User=User.Index Then
    MessWorkRecord6.User=SFalse
    If TreasureRecord.Occupants>False Then
       If MessWorkRecord6.Temp(1)>SFalse Then
          Var3=True
          MessWorkRecord6.User=MessWorkRecord6.Temp(1)
          For Var2=1 To 3
             MessWorkRecord6.Temp(Var2)=MessWorkRecord6.Temp(Var2+1)
          Next
          MessWorkRecord6.Temp(4)=SFalse
       Endif
    Endif
 Else
    For Var=1 To 4
       If MessWorkRecord6.Temp(Var)=User.Index Then
          For Var2=Var To 3
             MessWorkRecord6.Temp(Var2)=MessWorkRecord6.Temp(Var2+1)
          Next
          MessWorkRecord6.Temp(4)=SFalse
          Exit For
       Endif
    Next
 Endif
 Call Write.Record(RoomInvFile,Vehicle1)
 Var$=TreasureRecord.ShortName
 Var$=Rtrim$(Var$)
 Var$=Lcase$(Var$)
 Strng="You exit the "+Var$+"!"
 Call IO.O
 Var2$=UserRecord.CodeName
 Var2$=Rtrim$(Var2$)
 Var2$=Lcase$(Var2$)
 Mid$(Var2$,1,1)=UCase$(Mid$(Var2$,1,1))
 Var2$=Var2$+" exits the "+Var$+"!"
 Call Send.Vehicle(Var2$)
 If Var3 Then
    Var$="You are now owner of the vehicle!"
    Call Send.Mess(8,MessWorkRecord6.User,Room,Var$)
 Endif
 Vehicle1=SFalse
 Vehicle2=False
 Vehicle3=SFalse
ErrorResume13x2:
 Exit Sub
ErrorTrap13x2:
 Resume ErrorResume13x2
End Sub

' send message to all vehicle passengers except user.index
Sub Send.Vehicle(Var$)
 On Local Error Goto ErrorTrap13y2
 Call Read.Record(RoomInvFile,Vehicle1)
 Call Read.Record(TreasureFile,Vehicle3)
 Var2!=MessWorkRecord6.User
 If Var2!<>User.Index Then
    Call Send.Mess(8,Var2!,Room,Var$)
 Endif
 If TreasureRecord.Occupants>False Then
    For Var2=1 To 4
       Var2!=MessWorkRecord6.Temp(Var2)
       If Var2!>SFalse And Var2!<=Lof(UserFile)/UserRecLen Then
          If Var2!<>User.Index Then
             Call Send.Mess(8,Var2!,Room,Var$)
          Endif
       Endif
    Next
 Endif
ErrorResume13y2:
 Exit Sub
ErrorTrap13y2:
 Resume ErrorResume13y2
End Sub

' move all vehicle occupants.
Sub Update.Vehicles
 On Local Error Goto ErrorTrap13z2
 Call Read.Record(RoomInvFile,Vehicle1)
 Call Read.Record(TreasureFile,Vehicle3)
 Var2!=MessWorkRecord6.User
 If Var2!<>User.Index Then
    Var$=Str$(Next.Room)
    Call Send.Mess(36,Var2!,Room,Var$)
 Endif
 If TreasureRecord.Occupants>False Then
    For Var2=1 To 4
       Var2!=MessWorkRecord6.Temp(Var2)
       If Var2!>SFalse And Var2!<=Lof(UserFile)/UserRecLen Then
          If Var2!<>User.Index Then
             Var$=Str$(Next.Room)
             Call Send.Mess(36,Var2!,Room,Var$)
          Endif
       Endif
    Next
 Endif
ErrorResume13z2:
 Exit Sub
ErrorTrap13z2:
 Resume ErrorResume13z2
End Sub

Sub Clean.Room.Node(Var1!)
 On Local Error Goto ErrorTrap35
 If Var1!<=SFalse Or Var1!>Lof(RoomFile)/RoomRecLen Then
    Exit Sub
 Endif
 For VarX=False To MaxNodes
    If VarX<>Node Then
       Call Read.Message.Record(MessWorkFile1,VarX+1)
       Strng=Rtrim$(MessWorkRecord1.UserName)
       Call Valid.Name(Strng)
       If TempA Then
          If MessWorkRecord1.RoomNumber=Var1! Then
             Exit Sub
          Endif
       Endif
    Endif
 Next
 Call Read.Record(RoomFile,Var1!)
 If Config2(58)=False Then
    Temp5!=RoomRecord.First
    If Temp5! Then
       Do While Lost.Carrier=False
          Call Read.Record(RoomInvFile,Temp5!)
          If MessWorkRecord6.Room=SFalse Then
             Exit Do
          Endif
          Temp6!=MessWorkRecord6.Next
          If MessWorkRecord6.Plus=False Then
             Temp2!=MessWorkRecord6.Index
             If Temp2!>SFalse And Temp2!<=Lof(TreasureFile)/TreasureRecLen Then
                Call Read.Record(TreasureFile,Temp2!)
                If TreasureRecord.StaysInRoom=False Then
                   Call Delete.List.Node(Temp5!)
                   Call Clear.List.Node
                   Call Write.Record(RoomInvFile,Temp5!)
                Endif
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp5!=Temp6!
       Loop
    Endif
 Endif
 For Temp5!=1! To Lof(MessWorkFile3)/MessWorkRecLen3
    Call Read.Record(MessWorkFile3,Temp5!)
    If MessWorkRecord3.IsAutomaton=False Then
       If MessWorkRecord3.Monster.RemainsInRoom=False Then
          If MessWorkRecord3.Room=Var1! Then
             MessWorkRecord3.Room=SFalse
             Call Write.Record(MessWorkFile3,Temp5!)
          Endif
       Endif
    Endif
 Next
 For Temp5!=1! To Lof(MessWorkFile4)/MessWorkRecLen4
    Call Read.Record(MessWorkFile4,Temp5!)
    If MessWorkRecord4.Room=Var1! Then
       MessWorkRecord4.Room=SFalse
       Call Write.Record(MessWorkFile4,Temp5!)
    Endif
 Next
 For Temp5!=1! To Lof(MessWorkFile5)/MessWorkRecLen5
    Call Read.Record(MessWorkFile5,Temp5!)
    If MessWorkRecord5.Room=Var1! Then
       MessWorkRecord5.Room=SFalse
       Call Write.Record(MessWorkFile5,Temp5!)
    Endif
 Next
ErrorResume35:
 Exit Sub
ErrorTrap35:
 Resume ErrorResume35
End Sub

Sub New.Rates
 On Local Error Goto Err.Trap14
 Room=Next.Room
 Call Read.Record(RoomFile,Room)
 Call Status.Line(False)
 Monster.Rate1=False
 New.Room=True
 Room.Rate=False
 Rust.Rate=False
 Steal.Rate=False
Err.Resume14:
 Exit Sub
Err.Trap14:
 Resume Err.Resume14
End Sub

Sub Get.Ring.Hits(Var1,Var2)
 On Local Error Goto ErrorTrap15a
 If Var1 Then
    Var=UserRecord.Weapon(4).Charges
 Else
    Var=UserRecord.Weapon(9).Charges
 Endif
 Select Case Var2
 Case 1, 2
    Var=Var-MessWorkRecord3.Monster.Level
 Case 3
    Var=Var-SpellRecord.Level
 Case 4 To 9
    Var=Var-1
 End Select
 If Var1 Then
    UserRecord.Weapon(4).Charges=Var
 Else
    UserRecord.Weapon(9).Charges=Var
 Endif
 If Var1 Then
    Strng="Your left ring absorbs the "
 Else
    Strng="Your right ring absorbs the "
 Endif
 Select Case Var2
 Case 1
    Strng=Strng+"poison spell!"
 Case 2
    Strng=Strng+"level drain!"
 Case 3
    Strng=Strng+"spell!"
 Case 4
    Strng=Strng+"trap spell!"
 Case 5
    Strng=Strng+"rusting spell!"
 Case 6
    Strng=Strng+"stealing spell!"
 Case 7
    Strng=Strng+"inventory damage spell!"
 Case 8
    Strng=Strng+"fumble spell!"
 Case 9
    Strng=Strng+"teleport spell!"
 End Select
 Call IO.O
 If Var<=False Then
    If Var1 Then
       Strng="Your left ring disintegrated!"
       UserRecord.Weapon(4).Index=SFalse
       UserRecord.Weapon(4).Charges=False
       UserRecord.Weapon(4).Plus=False
    Else
       Strng="Your right ring disintegrated!"
       UserRecord.Weapon(9).Index=SFalse
       UserRecord.Weapon(9).Charges=False
       UserRecord.Weapon(9).Plus=False
    Endif
    Call IO.O
 Endif
ErrorResume15a:
 Exit Sub
ErrorTrap15a:
 Resume ErrorResume15a
End Sub

Sub Add.List.Node3(VarZ!)
 On Local Error Goto ErrorTrp27b
 If UserRecord.First=SFalse Then
    UserRecord.First=VarZ!
    UserRecord.Last=VarZ!
    Call Write.Record(UserFile,User.Index)
    MessWorkRecord6.Prev=SFalse
    MessWorkRecord6.Next=SFalse
    Call Write.Record(UserInvFile,VarZ!)
    Exit Sub
 Endif
 MessWorkRecord6.Prev=UserRecord.Last
 MessWorkRecord6.Next=SFalse
 Call Write.Record(UserInvFile,VarZ!)
 Call Read.Record(UserInvFile,UserRecord.Last)
 MessWorkRecord6.Next=VarZ!
 Call Write.Record(UserInvFile,UserRecord.Last)
 Call Read.Record(UserInvFile,VarZ!)
 UserRecord.Last=VarZ!
 Call Write.Record(UserFile,User.Index)
ErrorRsm27b:
 Exit Sub
ErrorTrp27b:
 Resume ErrorRsm27b
End Sub

Sub Update.Mess(Var)
 On Local Error Goto ErrorTrap2
 VarX2=Node+1
 Call Read.Message.Record(MessWorkFile1,VarX2)
 Select Case Var
 Case 1
    Strng="Login"
 Case 2
    Strng="Relogin"
 Case 3
    Strng="Logoff"
 Case Else
    Strng=UserRecord.CodeName
    Call Read.Node7
    Call Update.Node7
    Call Write.Record(UserFile,User.Index)
 End Select
 Call Make.Mess.Work1
 Call Write.Message.Record(MessWorkFile1,VarX2)
 If Next.Room>False Then
    Strng="You are teleported elsewhere!"
    Call IO.O
    Call Teleport
    Action.Recurse=0
    Call Enter.Room
 Endif
ErrorResume2:
 Exit Sub
ErrorTrap2:
 Resume ErrorResume2
End Sub

Sub Drop.Inventory(Var1!,Var2)
 On Local Error Goto ErrorTrp27
 VarX!=Lof(RoomInvFile)/MessWorkRecLen6+1!
 MessWorkRecord6.Room=Room
 MessWorkRecord6.User=SFalse
 MessWorkRecord6.Index=Var1!
 MessWorkRecord6.Charges=Var2
 MessWorkRecord6.Plus=False
 Call Write.Record(RoomInvFile,VarX!)
 Call Add.List.Node(VarX!)
ErrorRsm27:
 Exit Sub
ErrorTrp27:
 Resume ErrorRsm27
End Sub

Sub Add.Inventory(Var1!,Var2)
 On Local Error Goto ErrorTrp29
 VarQ1!=MessWorkRecord6.Desc(1)
 VarQ2!=MessWorkRecord6.Desc(2)
 VarQ3!=MessWorkRecord6.Desc(3)
 VarQ4!=MessWorkRecord6.Desc(4)
 Var!=Lof(MessWorkFile6)/MessWorkRecLen6+1!
 Temp0!=Var!
 If Var!=SFalse Then
    Exit Sub
 Endif
 MessWorkRecord6.User=User.Index
 MessWorkRecord6.Room=SFalse
 MessWorkRecord6.Index=Var1!
 MessWorkRecord6.Charges=Var2
 MessWorkRecord6.Plus=False
 MessWorkRecord6.Prev=SFalse
 MessWorkRecord6.Next=SFalse
 If Var1!>SFalse Then
    Weight=Weight+TreasureRecord.Weight
    VarX=TreasureRecord.Plus
    If TreasureRecord.Spell Then
       Call Read.Record(SpellFile,TreasureRecord.Spell)
       VarX=SpellRecord.Level
    Endif
    MessWorkRecord6.Plus=VarX
 Endif
 MessWorkRecord6.Desc(1)=VarQ1!
 MessWorkRecord6.Desc(2)=VarQ2!
 MessWorkRecord6.Desc(3)=VarQ3!
 MessWorkRecord6.Desc(4)=VarQ4!
 Call Write.Record(MessWorkFile6,Var!)
ErrorRsm29:
 Exit Sub
ErrorTrp29:
 Resume ErrorRsm29
End Sub

Sub Fumble
 On Local Error Goto ErrorTrap17
 If UserRecord.Weapon(7).Index Or UserRecord.Weapon(5).Index Then
    Strng="You fumbled! "
    Out2="You dropped your "
    Graphics.Off=True
    Carriage.Return=True
    Call IO.O
    Var1!=UserRecord.Weapon(5).Index
    If Var1! Then
       Call Read.Record(TreasureFile,Var1!)
       Out4=TreasureRecord.ShortName
       Out4=Rtrim$(Out4)
       Out4=Lcase$(Out4)
       Var2=UserRecord.Weapon(5).Charges
       Call Add.Inventory(Var1!,Var2)
       UserRecord.Weapon(5).Index=SFalse
       UserRecord.Weapon(5).Plus=False
       Call Discard(Temp0!,False)
       If UserRecord.Weapon(7).Index Then
          Strng=" and "+Out4
       Else
          Strng=Out2+Out4+"!"
       Endif
    Else
       Strng=Nul
    Endif
    Var1!=UserRecord.Weapon(7).Index
    If Var1! Then
       Call Read.Record(TreasureFile,Var1!)
       Out4=TreasureRecord.ShortName
       Out4=Rtrim$(Out4)
       Out4=Lcase$(Out4)
       Var2=UserRecord.Weapon(7).Charges
       Call Add.Inventory(Var1!,Var2)
       UserRecord.Weapon(7).Index=SFalse
       UserRecord.Weapon(7).Plus=False
       Call Discard(Temp0!,False)
       Strng=Out2+Out4+Strng+"!"
    Endif
    Call IO.O
    Graphics.Off=False
 Endif
ErrorResume17:
 Exit Sub
ErrorTrap17:
 Resume ErrorResume17
End Sub

Sub Teleport
 On Local Error Goto ErrTrap49
 If Node>False Then
    Out2=UserRecord.CodeName
    Out2=Lcase$(Out2)
    Out2=Rtrim$(Out2)
    Out2=Out2+" was just teleported away!"
    Call Send.Mess(8,SFalse,Room,Out2)
 Endif
 Teleported=True
ErrResume49:
 Exit Sub
ErrTrap49:
 Resume ErrResume49
End Sub

Sub Discard(Var1!,Var2)
 On Local Error Goto ErrorTrp28
 Call Read.Record(MessWorkFile6,Var1!)
 VarA!=MessWorkRecord6.Index
 VarB=MessWorkRecord6.Charges
 If VarA!>SFalse Then
    Call Read.Record(TreasureFile,VarA!)
    Weight=Weight-TreasureRecord.Weight
    If Weight<DFalse Then
       Weight=DFalse
    Endif
 Endif
 MessWorkRecord6.User=SFalse
 Call Write.Record(MessWorkFile6,Var1!)
 If Var2=False Then
    Call Drop.Inventory(VarA!,VarB)
 Endif
 For Var=1 To 4
    MessWorkRecord6.Desc(Var)=0!
 Next
 Call Write.Record(MessWorkFile6,Var1!)
ErrorRsm28:
 Exit Sub
ErrorTrp28:
 Resume ErrorRsm28
End Sub

Sub Make.Mess.Work1
 On Local Error Goto ErrorTrap3
 MessWorkRecord1.ActiveNode=True
 MessWorkRecord1.UserName=Strng
 MessWorkRecord1.ClassName=UserRecord.ClassName
 MessWorkRecord1.ClassType=UserRecord.ClassType
 MessWorkRecord1.Invisible=UserRecord.Invisible
 VarQ!=UserRecord.Weapon(8).Index
 If VarQ! Then
    Call Read.Record(TreasureFile,VarQ!)
    If TreasureRecord.Invisible Then
       MessWorkRecord1.Invisible=True
    Endif
 Endif
 MessWorkRecord1.Hidden=UserRecord.Hidden
 MessWorkRecord1.LastCommand=Last.Command
 MessWorkRecord1.Level=UserRecord.Level
 MessWorkRecord1.RoomNumber=Room
 MessWorkRecord1.Score1=Players.Killed
 MessWorkRecord1.Score2=Monsters.Killed
 MessWorkRecord1.Score3=Permanent.Killed
 MessWorkRecord1.TimeOn=Time.On
 MessWorkRecord1.UserIndex=User.Index
 MessWorkRecord1.Monitor=Monitor.Mode
 MessWorkRecord1.Chatting=Chat.Mode
 MessWorkRecord1.Gold=UserRecord.Gold
 MessWorkRecord1.Exp=UserRecord.Experience
 MessWorkRecord1.LastMonster=Monster.Attacked
 MessWorkRecord1.LastUser=User.Attacked
ErrorResume3:
 Exit Sub
ErrorTrap3:
 Resume ErrorResume3
End Sub

Sub Update.Node7
 On Local Error Goto ErrorTrap4
 MessWorkRecord7.CodeName=UserRecord.CodeName
 MessWorkRecord7.PassWord=UserRecord.PassWord3
 MessWorkRecord7.Level=UserRecord.Level
 MessWorkRecord7.ClassType=UserRecord.ClassType
 MessWorkRecord7.Proficiency=UserRecord.Proficiency
 MessWorkRecord7.Weapon1=UserRecord.Weapons(1)
 MessWorkRecord7.Weapon2=UserRecord.Weapons(2)
 MessWorkRecord7.Weapon3=UserRecord.Weapons(3)
 MessWorkRecord7.Weapon4=UserRecord.Weapons(4)
 MessWorkRecord7.Classname=UserRecord.Classname
 MessWorkRecord7.Stat1=UserRecord.Stats(1)
 MessWorkRecord7.Stat2=UserRecord.Stats(2)
 MessWorkRecord7.Stat3=UserRecord.Stats(3)
 MessWorkRecord7.Stat4=UserRecord.Stats(4)
 MessWorkRecord7.Stat5=UserRecord.Stats(5)
 MessWorkRecord7.Stat6=UserRecord.Stats(6)
 MessWorkRecord7.Stat7=UserRecord.Stats(7)
 MessWorkRecord7.Stat8=UserRecord.Beauty
 MessWorkRecord7.Stat9=UserRecord.Glamour
 MessWorkRecord7.Experience=UserRecord.Experience
 MessWorkRecord7.Gold=UserRecord.Gold
 MessWorkRecord7.Room=Room
 MessWorkRecord7.TimeLimit=UserRecord.TimeLimit
 MessWorkRecord7.MaxCalls=UserRecord.MaxCalls
 MessWorkRecord7.FromHour=UserRecord.FromHour
 MessWorkRecord7.FromMin=UserRecord.FromMin
 MessWorkRecord7.ToHour=UserRecord.ToHour
 MessWorkRecord7.ToMin=UserRecord.ToMin
 MessWorkRecord7.SpecialFlags=UserRecord.Flags
 MessWorkRecord7.Race=UserRecord.Race
 MessWorkRecord7.FatigueMax=UserRecord.FatigueMax
 MessWorkRecord7.VitalityMax=UserRecord.VitalityMax
 MessWorkRecord7.MagicMax=UserRecord.MagicMax
 MessWorkRecord7.PsionicMax=UserRecord.PsionicMax
 MessWorkRecord7.Align1=UserRecord.Align1
 MessWorkRecord7.Align2=UserRecord.Align2
 MessWorkRecord7.First2=UserRecord.First2
 MessWorkRecord7.Last2=UserRecord.Last2
 MessWorkRecord7.Weight=False
 MessWorkRecord7.Vehicle=SFalse
 MessWorkRecord7.NodeList=UserRecord.NodeList2
 MessWorkRecord7.WishesLeft=UserRecord.WishsLeft
 MessWorkRecord7.NodeList2=UserRecord.NodeList
 MessWorkRecord7.Prefix1=UserRecord.Prefix1
 MessWorkRecord7.Prefix2=UserRecord.Prefix2
 For VarQ=1 To 10
    MessWorkRecord7.ObjCreated(VarQ)=UserRecord.ObjectsCreated(VarQ)
 Next
 MessWorkRecord7.Flags1=False
 MessWorkRecord7.Flags2=False
 MessWorkRecord7.Flags3=False
 MessWorkRecord7.Flags4=False
 MessWorkRecord7.Flags5=False
 VarX2=Node+1
 Call Write.Message.Record(MessWorkFile7,VarX2)
ErrorResume4:
 Exit Sub
ErrorTrap4:
 Resume ErrorResume4
End Sub

Sub Read.Node7
 On Local Error Goto ErrorTrap5
 Next.Room=SFalse
 VarX2=Node+1
 Call Read.Message.Record(MessWorkFile7,VarX2)
 Var1=MessWorkRecord7.Flags1
 Var2=MessWorkRecord7.Flags2
 Var3=MessWorkRecord7.Flags3
 Var4=MessWorkRecord7.Flags4
 Var5=MessWorkRecord7.Flags5
 If Var1=False And Var2=False And Var3=False And Var4=False And Var5=False Then
    Exit Sub
 Endif
 If Var1 Then
    For VarQ=1 To 10
       If (Var1 And 2^VarQ)=2^VarQ Then
          Select Case VarQ
          Case 1
             UserRecord.CodeName=MessWorkRecord7.CodeName
          Case 2
             Strng2=MessWorkRecord7.PassWord
             Strng2=Rtrim$(Strng2)
             UserRecord.PassWord3=Strng2
             Call Crypto(Strng2)
             Call Cryptograph(Strng2)
             UserRecord.PassWord=Strng2
          Case 3
             UserRecord.Level=MessWorkRecord7.Level
          Case 4
             UserRecord.ClassType=MessWorkRecord7.ClassType
          Case 5
             UserRecord.Proficiency=MessWorkRecord7.Proficiency
          Case 6
             UserRecord.Weapons(1)=MessWorkRecord7.Weapon1
          Case 7
             UserRecord.Weapons(2)=MessWorkRecord7.Weapon2
          Case 8
             UserRecord.Weapons(3)=MessWorkRecord7.Weapon3
          Case 9
             UserRecord.Weapons(4)=MessWorkRecord7.Weapon4
          Case 10
             UserRecord.Classname=MessWorkRecord7.Classname
          End Select
       Endif
    Next
 Endif
 If Var2 Then
    For VarQ=1 To 10
       If (Var2 And 2^VarQ)=2^VarQ Then
          Select Case VarQ
          Case 1
             UserRecord.Stats(1)=MessWorkRecord7.Stat1
          Case 2
             UserRecord.Stats(2)=MessWorkRecord7.Stat2
          Case 3
             UserRecord.Stats(3)=MessWorkRecord7.Stat3
          Case 4
             UserRecord.Stats(4)=MessWorkRecord7.Stat4
          Case 5
             UserRecord.Stats(5)=MessWorkRecord7.Stat5
          Case 6
             UserRecord.Stats(6)=MessWorkRecord7.Stat6
          Case 7
             UserRecord.Stats(7)=MessWorkRecord7.Stat7
          Case 8
             UserRecord.Experience=MessWorkRecord7.Experience
          Case 9
             UserRecord.Gold=MessWorkRecord7.Gold
          Case 10
             Next.Room=MessWorkRecord7.Room
          End Select
       Endif
    Next
 Endif
 If Var3 Then
    For VarQ=1 To 10
       If (Var3 And 2^VarQ)=2^VarQ Then
          Select Case VarQ
          Case 1
             UserRecord.TimeLimit=MessWorkRecord7.TimeLimit
          Case 2
             UserRecord.MaxCalls=MessWorkRecord7.MaxCalls
          Case 3
             UserRecord.FromHour=MessWorkRecord7.FromHour
          Case 4
             UserRecord.FromMin=MessWorkRecord7.FromMin
          Case 5
             UserRecord.ToHour=MessWorkRecord7.ToHour
          Case 6
             UserRecord.ToMin=MessWorkRecord7.ToMin
          Case 7
             UserRecord.Flags=MessWorkRecord7.SpecialFlags
          Case 8
             UserRecord.Race=MessWorkRecord7.Race
          Case 9
             UserRecord.Fatigue=MessWorkRecord7.FatigueMax
             UserRecord.FatigueMax=MessWorkRecord7.FatigueMax
          CAse 10
             UserRecord.Vitality=MessWorkRecord7.VitalityMax
             UserRecord.VitalityMax=MessWorkRecord7.VitalityMax
          End Select
       Endif
    Next
 Endif
 If Var4 Then
    For VarQ=1 To 10
       If (Var4 And 2^VarQ)=2^VarQ Then
          Select Case VarQ
          Case 1
             UserRecord.Magic=MessWorkRecord7.MagicMax
             UserRecord.MagicMax=MessWorkRecord7.MagicMax
          Case 2
             UserRecord.Psionic=MessWorkRecord7.PsionicMax
             UserRecord.PsionicMax=MessWorkRecord7.PsionicMax
          Case 3
             UserRecord.Align1=MessWorkRecord7.Align1
          Case 4
             UserRecord.Align2=MessWorkRecord7.Align2
          Case 5
             Monster.Attacked=False
          Case 6
             User.Attacked=False
          Case 7
             UserRecord.Encumbrance=MessWorkRecord7.Encumbrance
          Case 8
             UserRecord.First2=MessWorkRecord7.First2
             UserRecord.Last2=MessWorkRecord7.Last2
             Weight=Weight-MessWorkRecord7.Weight
             If Weight<DFalse Then
                Weight=DFalse
             Endif
          Case 9
             UserRecord.First2=MessWorkRecord7.First2
             UserRecord.Last2=MessWorkRecord7.Last2
             Weight=Weight+MessWorkRecord7.Weight
          Case 10
             Vehicle1=MessWorkRecord7.Vehicle
          End Select
       Endif
    Next
 Endif
 If Var5 Then
    For VarQ=1 To 8
       If (Var5 And 2^VarQ)=2^VarQ Then
          Select Case VarQ
          Case 1
             UserRecord.Beauty=MessWorkRecord7.Stat8
          Case 2
             UserRecord.Glamour=MessWorkRecord7.Stat9
          Case 3
             UserRecord.NodeList2=MessWorkRecord7.NodeList
          Case 4
             UserRecord.WishsLeft=MessWorkRecord7.WishesLeft
          Case 5
             UserRecord.NodeList=MessWorkRecord7.NodeList2
          Case 6
             UserRecord.Prefix1=MessWorkRecord7.Prefix1
          Case 7
             UserRecord.Prefix2=MessWorkRecord7.Prefix2
          Case 8
             For VarZ=1 To 10
                UserRecord.ObjectsCreated(VarZ)=MessWorkRecord7.ObjCreated(VarZ)
             Next
          End Select
       Endif
    Next
 Endif
ErrorResume5:
 Exit Sub
ErrorTrap5:
 Resume ErrorResume5
End Sub

Sub Hit.Player(Var)
 On Local Error Goto ErrorTrap16
 If Var>False Then
    If UserRecord.Fatigue-Var>=False Then
       UserRecord.Fatigue=UserRecord.Fatigue-Var
       Strng=Strng+Str$(Var)+" fatigue points!"
       Call IO.O
       Exit Sub
    Endif
    Var=Var-UserRecord.Fatigue
    If UserRecord.Fatigue>False Then
       Strng=Strng+Str$(UserRecord.Fatigue)+" fatigue and"
    Endif
    UserRecord.Fatigue=False
 Endif
 Var1=Abs(Var)
 If Var1>False Then
    Strng=Strng+Str$(Var1)+" vitality points!"
    Call IO.O
    If UserRecord.Vitality-Var1<=False Then
       UserRecord.Vitality=False
       Message1="You were just killed!"
       Strng="was killed by "+Prefix2+Out3
       Call Update.DayFile(Strng,False,1)
       Call Player.Died
       Exit Sub
    Endif
    UserRecord.Vitality=UserRecord.Vitality-Var1
 Endif
ErrorResume16:
 Exit Sub
ErrorTrap16:
 Resume ErrorResume16
End Sub

' verifies next room number exists.
Sub Check.Room.Number(Temp.Room!)
 On Local Error Goto ErrorTrp35
 ' store last room number in room file.
 Last.Room!=Lof(RoomFile)/RoomRecLen
 Do While Lost.Carrier=False
    ' check next room is within existing range.
    If Temp.Room!>SFalse And Temp.Room!<=Last.Room! Then
       Exit Do
    Endif
    ' if not, check to see if DM can create one.
    If Normal.User=False Then
       ' get DM create room.
       Call Add.Room(VarX)
       ' check room created.
       If VarX Then
          Exit Do
       Endif
    Endif
    ' if not, check default nondescrip room number to move to within range.
    Var!=Csng(Config2(15))
    If Var!>SFalse And Var!<=Last.Room! Then
       Temp.Room!=Var!
       Graphics.Off=False
       Strng="Nondescriptive room number!"
       Call IO.O
       Strng="Moving you to room"+Str$(Temp.Room!)+"."
       Call IO.O
       Exit Do
    Endif
    ' if not, check if room #1 within range.
    If Last.Room!>SFalse Then
       Temp.Room!=1!
       Graphics.Off=False
       Strng="Nondescriptive room number!"
       Call IO.O
       Strng="Moving you to room one."
       Call IO.O
       Exit Do
    Endif
    ' otherwise move to no existing room number.
    Temp.Room!=SFalse
    ' check for hangup due to nondescrip & nonexisting room.
    If Config2(16) Then
       Call Hang.Up(10)
    Endif
    ' return anyway!?
    Strng="Nondescriptive room file!"
    Call IO.O
    Exit Do
 Loop
ErrorRsm35:
 Exit Sub
ErrorTrp35:
 Resume ErrorRsm35
End Sub

Sub Add.List.Node(VarZ!)
 On Local Error Goto ErrorTrp27a
 Call Read.Record(RoomFile,Room)
 If RoomRecord.First=SFalse Then
    RoomRecord.First=VarZ!
    RoomRecord.Last=VarZ!
    Call Write.Record(RoomFile,Room)
    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,Room)
ErrorRsm27a:
 Exit Sub
ErrorTrp27a:
 Resume ErrorRsm27a
End Sub

Sub Find.Back.Link(Var2)
 On Local Error Goto ErrorTrap50
 Select Case Var2
 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
ErrorResume50:
 Exit Sub
ErrorTrap50:
 Resume ErrorResume50
End Sub

Sub Clear.Room
 On Local Error Goto ErrorTrap31
 Next.Room=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.ShortDesc=Nul
 RoomRecord.MonClass=SFalse
 RoomRecord.First=SFalse
 RoomRecord.Last=SFalse
 RoomRecord.First2=SFalse
 RoomRecord.Last2=SFalse
 Call Write.Record(RoomFile,Next.Room)
ErrorResume31:
 Exit Sub
ErrorTrap31:
 Resume ErrorResume31
End Sub

Sub Open.Shell.Files
 On Local Error Goto Open.Error1
 FileName=Action.Filename
 Open FileName For Random Shared As #ActionFile Len=ActionRecLen
 FileName=Container.FileName
 Open FileName For Random Shared As #ContainerFile Len=ContainerRecLen
 FileName=Message.Base.FileName
 Open FileName For Random Shared As #MessBaseFile Len=MessBaseRecLen
 FileName=Monster.FileName
 Open FileName For Random Shared As #MonsterFile Len=MonsterRecLen
 FileName=MonClass.FileName
 Open FileName For Random Shared As #MonClassFile Len=MonClassRecLen
 FileName=MonTalk.FileName
 Open FileName For Random Shared As #MonTalkFile Len=MonTalkRecLen
 FileName=NonPlayer.FileName
 Open FileName For Random Shared As #NonPlayerFile Len=NonPlayerRecLen
 FileName=Object.FileName
 Open FileName For Random Shared As #ObjectFile Len=ObjectRecLen
 FileName=Room.FileName
 Open FileName For Random Shared As #RoomFile Len=RoomRecLen
 FileName=Room.Desc.FileName
 Open FileName For Random Shared As #RoomDescFile Len=RoomDescLen
 FileName=Spell.FileName
 Open FileName For Random Shared As #SpellFile Len=SpellRecLen
 FileName=Team.FileName
 Open FileName For Random Shared As #TeamFile Len=TeamRecLen
 FileName=Treasure.FileName
 Open FileName For Random Shared As #TreasureFile Len=TreasureRecLen
 FileName=User.FileName
 Open FileName For Random Shared As #UserFile Len=UserRecLen
 Open FileName For Random Shared As #UserFile2 Len=UserRecLen
 FileName=UserInv.FileName
 Open FileName For Random Shared As #UserInvFile Len=MessWorkRecLen6
 FileName=CtnInv.FileName
 Open FileName For Random Shared As #CtnInvFile Len=MessWorkRecLen6
 FileName=TeamInv.FileName
 Open FileName For Random Shared As #TeamInvFile Len=MessWorkRecLen6
 FileName=RoomInv.FileName
 Open FileName For Random Shared As #RoomInvFile Len=MessWorkRecLen6
 FileName=MonInv.FileName
 Open FileName For Random Shared As #MonInvFile Len=MessWorkRecLen6
 Exit Sub
Open.Error1:
 Temp=Err
 Call Error.Message(1,Temp)
End Sub

Sub Open.Node.Files
 On Local Error Goto Open.Error2
 FileName=MessWork.FileName+"1"+File.Extension1
 Open FileName For Random Shared As #MessWorkFile1 Len=MessWorkRecLen1
 FileName=MessWork.FileName+"2"+File.Extension1
 Open FileName For Random Shared As #MessWorkFile2 Len=MessWorkRecLen2
 FileName=MessWork.FileName+"3"+File.Extension1
 Open FileName For Random Shared As #MessWorkFile3 Len=MessWorkRecLen3
 FileName=MessWork.FileName+"4"+File.Extension1
 Open FileName For Random Shared As #MessWorkFile4 Len=MessWorkRecLen4
 FileName=MessWork.FileName+"5"+File.Extension1
 Open FileName For Random Shared As #MessWorkFile5 Len=MessWorkRecLen5
 FileName=MessWork.FileName+"6"+File.Extension1
 Open FileName For Random Shared As #MessWorkFile6 Len=MessWorkRecLen6
 FileName=MessWork.FileName+"7"+File.Extension1
 Open FileName For Random Shared As #MessWorkFile7 Len=MessWorkRecLen7
 FileName=Data.Path3+Config3(69)+NodeX+File.Extension1
 Open FileName For Random Shared As #MessWorkFile8 Len=UserCommandLen
 Exit Sub
Open.Error2:
 Temp=Err
 Call Error.Message(2,Temp)
End Sub

Sub Open.Temp.Files
 On Local Error Goto Open.Error3
 FileName=Data.Path3+Config3(69)+NodeX+File.Extension1
 Open FileName For Random Shared As #MessageFile
 Open FileName For Random Shared As #NewFile
 Open FileName For Random Shared As #TableFile
 Open FileName For Random Shared As #LogFile
 Open FileName For Random Shared As #DayFile1
 Open FileName For Random Shared As #TempFile1
 Open FileName For Random Shared As #TempFile2
 Open FileName For Random Shared As #HelpFile1
 Open FileName For Random Shared As #HelpFile2
 Open FileName For Random Shared As #HelpFile3
 Open FileName For Random Shared As #SicFile
 Open FileName For Random Shared As #DiskFile
 Open FileName For Random Shared As #PrintFile
 Exit Sub
Open.Error3:
 Temp=Err
 Call Error.Message(3,Temp)
End Sub

Sub Close.Files
 On Local Error Goto Error.Trap6
 Close #ActionFile, #ContainerFile, #MessBaseFile, #MonsterFile, #MonClassFile,_
 #MonTalkFile, #NonPlayerFile, #ObjectFile, #RoomFile, #RoomDescFile, #SpellFile, #TeamFile,_
 #TreasureFile, #UserFile, #UserFile2, #UserInvFile, #CtnInvFile, #TeamInvFile, #RoomInvFile, #MonInvFile
Error.Resume6:
 Exit Sub
Error.Trap6:
 Resume Error.Resume6
End Sub

Sub Close.Nodes
 On Local Error Goto Error.Trap7
 Close #MessWorkFile1, #MessWorkFile2, #MessWorkFile3, #MessWorkFile4,_
 #MessWorkFile5, #MessWorkFile6, #MessWorkFile7, #MessWorkFile8
Error.Resume7:
 Exit Sub
Error.Trap7:
 Resume Error.Resume7
End Sub

Sub Close.Temp
 On Local Error Goto Error.Trap8
 Close #MessageFile, #NewFile, #TableFile, #LogFile, #DayFile1, #TempFile1,_
 #TempFile2, #HelpFile1, #HelpFile2, #HelpFile3, #SicFile,_
 #DiskFile, #PrintFile
Error.Resume8:
 Exit Sub
Error.Trap8:
 Resume Error.Resume8
End Sub

Sub Error.Message(Var,Var2)
 On Local Error Goto Error.Trap10
 Select Case Var2
 Case 53
    Strng=" file not found"
 Case 55
    Strng=" file already open"
 Case 57
    Strng=" media error"
 Case 61
    Strng=" disk full"
 Case 62
    Strng=" input past eof"
 Case 67
    Strng=" not enough file handles"
 Case 68
    Strng=" device unavailable"
 Case 70
    Strng=" permission denied"
 Case 71
    Strng=" disk not ready"
 Case Else
    Strng=Str$(Var2)
 End Select
 Out2="File error("+Mid$(Str$(Var),2)+":"
 Out2=Out2+Strng+") processing "+Lcase$(FileName)+"."
 Out3="Increase files= in config.sys or config.nt file, or run Dndcnfg."
Error.Resume10:
 Call Terminate.Program
 Exit Sub
Error.Trap10:
 Resume Error.Resume10
End Sub

Sub Terminate.Program
 On Local Error Goto Error.Trap1
 Call ScreenANSI(4,37,15)
 Call ScreenANSI(2,Max.Row,1)
 If Len(Out2) Then
    Strng=Out2
    Call Scroll.Row(1)
 Endif
 If Len(Out3) Then
    Strng=Out3
    Call Scroll.Row(1)
 Endif
 Print
 Call Exit.To.DOS
Error.Resume1:
 End
Error.Trap1:
 Resume Error.Resume1
End Sub

Sub Exit.To.DOS
 On Local Error Goto Error.Trap2
 Call Extended.Driver(29)
 Call Decrease.Files
 Call Modem.ANSI(1,37,7)
 Call ScreenANSI(4,33,7)
 Call ScreenANSI(2,Max.Row,1)
 If BBS.Mode Then
    Strng="Returning you to: "
    If Rtrim$(BBS.Name)=Nul Then
       Strng=Strng+"<n/a>"
    Else
       Strng=Strng+BBS.Name
    Endif
 Else
    If Windows.Detected Then
       Strng="Returning you to Windows Dos."
    Else
       Strng="Returning you to Dos."
    Endif
 Endif
 Call Scroll.Row(1)
 Call ScreenANSI(1,37,7)
 Color 7,0
 If Mouse.Present Then
    Call Mouse.Function(2,0)
 Endif
Error.Resume2:
 Exit Sub
Error.Trap2:
 Resume Error.Resume2
End Sub

Sub Decrease.Files
 On Local Error Goto Error.trap3
 Close
 Call StdinInt(62,0)
 PSP.Segment=OutregsX.BX
 Def Seg=PSP.Segment
 Poke &H32,20
 Poke &H34,&H18
 Def Seg
 Close
Error.Resume3:
 Exit Sub
Error.Trap3:
 Print "Error"+Str$(Err)+" closing file handles. Free more RAM."
 Resume Error.Resume3
End Sub

Sub Get.Weapon.Hits
 On Local Error Goto ErrorTrap14
 For VarX=1 To 6
    Select Case VarX
    Case 1, 2, 3, 5, 6
       Var1!=UserRecord.Weapon(VarX).Index
       If Var1! Then
          Var2=UserRecord.Weapon(VarX).Charges
          Var2=Var2-1
          UserRecord.Weapon(VarX).Charges=Var2
          If Var2<=False Then
             Call Read.Record(TreasureFile,Var1!)
             Out2=TreasureRecord.ShortName
             Out2=Rtrim$(Out2)
             Out2=Lcase$(Out2)
             Select Case VarX
             Case 1
                Strng="crumbles"
             Case 2
                Strng="falls apart"
             Case 3
                Strng="cracks"
             Case 5
                Strng="breaks in half"
             Case 6
                Strng="falls off"
             End Select
             Strng="Your "+Out2+" "+Strng+"!"
             Call IO.O
             Call Add.Inventory(Var1!,Var2)
             UserRecord.Weapon(VarX).Index=SFalse
             UserRecord.Weapon(VarX).Plus=False
             Call Discard(Temp0!,False)
          Endif
       Endif
    End Select
 Next
ErrorResume14:
 Exit Sub
ErrorTrap14:
 Resume ErrorResume14
End Sub

Sub Check.User.Items2
 On Local Error Goto ErrorTrp17b
 Temp6=False
 Temp7!=SFalse
 TempC=False
 If Parsed.Command1<>Nul Then
    For Temp5!=1! To Lof(MessWorkFile6)/MessWorkRecLen6
       Call Read.Record(MessWorkFile6,Temp5!)
       If MessWorkRecord6.User=User.Index Then
          VarQ!=MessWorkRecord6.Index
          If VarQ!<SFalse Then
             VarA!=Abs(VarQ!)
             If VarA!>SFalse And VarA!<=Lof(ObjectFile)/ObjectRecLen Then
                Call Read.Record(ObjectFile,VarA!)
                Out3=Rtrim$(ObjectRecord.ShortName)
                If Out3=Parsed.Command1 Then
                   TempC=TempC+1
                   If Parse.Temp=False Or TempC=Parse.Temp Then
                      Out3=ObjectRecord.ObjectName
                      Out3=Rtrim$(Out3)
                      Temp7!=VarQ!
                      Temp6=MessWorkRecord6.Charges
                      Exit For
                   Endif
                Endif
             Endif
          Endif
          If VarQ!>SFalse Then
             If VarQ!>SFalse And VarQ!<=Lof(TreasureFile)/TreasureRecLen Then
                Call Read.Record(TreasureFile,VarQ!)
                Out3=Rtrim$(TreasureRecord.ShortName)
                If Out3=Parsed.Command1 Then
                   TempC=TempC+1
                   If Parse.Temp=False Or TempC=Parse.Temp Then
                      Out3=TreasureRecord.TreasureName
                      Out3=Rtrim$(Out3)
                      Temp7!=VarQ!
                      Temp6=MessWorkRecord6.Charges
                      Exit For
                   Endif
                Endif
             Endif
          Endif
       Endif
    Next
 Endif
ErrorRsm17b:
 Exit Sub
ErrorTrp17b:
 Resume ErrorRsm17b
End Sub

Sub Check.Monster
 On Local Error Goto ErrorTrp20
 Temp5!=SFalse
 TempC=False
 Monster.Temp=SFalse
 If Parsed.Command1<>Nul Then
    For Temp5!=1! To Lof(MessWorkFile3)/MessWorkRecLen3
       Call Read.Record(MessWorkFile3,Temp5!)
       If MessWorkRecord3.Room=Room Then
          TempA=False
          TempB=False
          Out3=MessWorkRecord3.Monster.MonsterName
          Out3=Rtrim$(Out3)
          Out3=Ucase$(Out3)
          TempA=Instr(TempA+1,Out3," ")
          While TempA
             TempB=TempA
             TempA=Instr(TempA+1,Out3," ")
          Wend
          Out2=Mid$(Out3,TempB+1)
          Out2=Left$(Out2,Len(Parsed.Command1))
          If Out2=Parsed.Command1 Then
             TempC=TempC+1
             If Parse.Temp=False Or TempC=Parse.Temp Then
                Out3=MessWorkRecord3.Monster.MonsterName
                Out3=Rtrim$(Out3)
                Choice=MessWorkRecord3.Index
                Monster.Temp=Temp5!
                Last.Monster=Parsed.Command1
                Exit For
             Endif
          Endif
       Endif
    Next
 Endif
ErrorRsm20:
 Exit Sub
ErrorTrp20:
 Resume ErrorRsm20
End Sub

Sub Hit.Monster
 On Local Error Goto ErrorTrap3a
 Hidden.Player=False
 If Config2(63) Then
    Out2=Config3(30)
    If Magic.Spell=False Then
       If Last.Command.Number=PsiMode Then
          Out2=Config3(43)
       Endif
    Else
       If SpellRecord.Equation=True Then
          Out2=SpellRecord.SpellEquate
          Out2=Rtrim$(Out2)
       Endif
    Endif
    Call Equate(Temp#)
 Else
    If Last.Command.Number=PsiMode Then
       Temp#=Int(Rnd*UserRecord.Stats(2)+UserRecord.Stats(3)*_
       (Psi.Attack.Mode+Multiplier))
    Else
       Temp#=Int((Rnd*UserRecord.Stats(1)+UserRecord.Level/2)*_
       (Multiplier+(UserRecord.Weapons(UserRecord.Proficiency)/100))-_
       MessWorkRecord3.Weapon(2).Plus/2-_
       MessWorkRecord3.Weapon(3).Plus/2+_
       Abs(UserRecord.Weapon(7).Plus))
    Endif
 Endif
 If Magic.Spell=False Then
    If Last.Command.Number<>PsiMode Then
       If MessWorkRecord3.Weapon(2).Charges>0 Then
          MessWorkRecord3.Weapon(2).Charges=MessWorkRecord3.Weapon(2).Charges-1
          If MessWorkRecord3.Weapon(2).Charges=0 Then
             MessWorkRecord3.Weapon(2).Plus=0
             Call Write.Record(MessWorkFile3,Monster.Temp)
          Endif
       Else
          If MessWorkRecord3.Weapon(3).Charges>0 Then
             MessWorkRecord3.Weapon(3).Charges=MessWorkRecord3.Weapon(3).Charges-1
             If MessWorkRecord3.Weapon(3).Charges=0 Then
                MessWorkRecord3.Weapon(3).Plus=0
                Call Write.Record(MessWorkFile3,Monster.Temp)
             Endif
          Endif
       Endif
    Endif
 Endif
 Magic.Spell=False
 If Temp#>MaxInt Then
    Temp2=MaxInt
 Else
    Temp2=Int(Temp#)
 Endif
 Graphics.Off=False
 If Temp2<=False Then
    Strng="You missed the "+Out3+"!"
    Call IO.O
    Call Team.Hit.Monster
    Exit Sub
 Endif
 Strng="You hit the "+Out3+" for "
 Select Case Temp2
 Case 1
    Strng=Strng+"one hit.."
 Case 2 To 10
    Strng=Strng+Rtrim$(Numeral(Temp2))+" hits!"
 Case Else
    Strng=Strng+Form$(Cdbl(Temp2))+" hits!"
 End Select
 Call IO.O
 If MessWorkRecord3.Monster.Magic>=False Then
    If MessWorkRecord3.Monster.Permanent=False Then
       If MessWorkRecord3.Monster.Hits-Temp2>False Then
          If Temp2>MessWorkRecord3.Monster.Hits*Config1(14) Then
             Strng="The "+Out3+" flees from your attack!"
             Call IO.O
             MessWorkRecord3.Monster.Experience=_
             Int(MessWorkRecord3.Monster.Experience/2)
             Call Write.Record(MessWorkFile3,Monster.Temp)
             Call Monster.Died
             Exit Sub
          Endif
       Endif
    Endif
 Endif
 If MessWorkRecord3.Monster.Magic=True Then
    MessWorkRecord3.Monster.Magic=-2
 Endif
 MessWorkRecord3.Monster.Hits=MessWorkRecord3.Monster.Hits-Temp2
 Call Write.Record(MessWorkFile3,Monster.Temp)
 If MessWorkRecord3.Monster.Hits<=False Then
    Strng="You just killed the "+Out3+"!"
    Call IO.O
    Call Monster.Died
    Exit Sub
 Endif
 Call Team.Hit.Monster
ErrorResume3a:
 Exit Sub
ErrorTrap3a:
 Resume ErrorResume3a
End Sub

Sub Team.Hit.Monster
 On Local Error Goto ErrorTrap4x
 If Config2(19)=0 Then ' offline user fights
    Exit Sub
 Endif
 For User.Temp=1! To Lof(MessWorkFile4)/MessWorkRecLen4
    Call Read.Record(MessWorkFile4,User.Temp)
    If MessWorkRecord4.Room=Room Then
       Call Read.Record(UserFile2,MessWorkRecord4.Index)
       Out4=Lcase$(Rtrim$(UserRecord2.CodeName))
       Var4=False
       For Var!=1! To Lof(TeamFile)/TeamRecLen
          Call Read.Record(TeamFile,Var!)
          If TeamRecord.Deleted=False Then
             For VarY=1 To MaxTeamMembers
                Var2!=TeamRecord.UserIndex(VarY)
                If Var2!=User.Index Then
                   For VarZ=1 To MaxTeamMembers
                      Var2!=TeamRecord.UserIndex(VarZ)
                      If Var2!=MessWorkRecord4.Index Then
                         If TeamRecord.Activated(VarZ) Then
                            Call Team.Hits
                            Var4=True
                            Exit For
                         Endif
                      Endif
                   Next
                   If Var4 Then
                      Exit For
                   Endif
                Endif
             Next
             If Var4 Then
                Exit For
             Endif
          Endif
       Next
    Endif
 Next
ErrorResume4x:
 Exit Sub
ErrorTrap4x:
 Resume ErrorResume4x
End Sub

Sub Team.Hits
 On Local Error Goto ErrorTrap4y
 Gosub Get.Config3
 Call New.Stats2(Var5)
 If Var5 Then
    Exit Sub
 Endif
 Select Case UserRecord2.Weapon(7).Plus
 Case False
    Strng="Punch!"
    Call IO.O
    Multiplier2=Config2(43)
 Case Else
    Select Case Rnd
    Case Is>Config1(25)
       Strng="Deathly damage!"
       Call IO.O
       Multiplier2=Config2(40)
    Case Is>Config1(26)
       Strng="Triple damage!"
       Call IO.O
       Multiplier2=Config2(41)
    Case Is>Config1(27)
       Strng="Double damage!"
       Call IO.O
       Multiplier2=Config2(42)
    End Select
 End Select
 If Len(option1$) Then
    Out2=option1$
    Call Equate(Temp#)
 Else
    Temp#=Int((Rnd*UserRecord2.Stats(1)+UserRecord2.Level/2)*_
    (Multiplier2+(UserRecord2.Weapons(UserRecord2.Proficiency)/100))-_
    MessWorkRecord3.Weapon(2).Plus/2-_
    MessWorkRecord3.Weapon(3).Plus/2+_
    Abs(UserRecord2.Weapon(7).Plus))
 Endif
 If Temp#>MaxInt Then
    Temp2=MaxInt
 Else
    Temp2=Int(Temp#)
 Endif
 If Len(Out4) Then
    Mid$(Out4,1,1)=Ucase$(Mid$(Out4,1,1))
 Endif
 Graphics.Off=False
 If Temp2<=False Then
    Strng=Out4+" missed!"
    Call IO.O
    Exit Sub
 Endif
 Out3=Lcase$(Out3)
 Strng=Out4+" hits the "+Out3+" for "
 Select Case Temp2
 Case 1
    Strng=Strng+"one hit.."
 Case 2 To 10
    Strng=Strng+Rtrim$(Numeral(Temp2))+" hits!"
 Case Else
    Strng=Strng+Form$(Cdbl(Temp2))+" hits!"
 End Select
 Call IO.O
 If MessWorkRecord3.Monster.Magic=True Then
    MessWorkRecord3.Monster.Magic=-2
 Endif
 MessWorkRecord3.Monster.Hits=MessWorkRecord3.Monster.Hits-Temp2
 Call Write.Record(MessWorkFile3,Monster.Temp)
 If MessWorkRecord3.Monster.Hits<=False Then
    Strng=Out4+" just killed the "+Out3+"!"
    Call IO.O
    Call Monster.Died
    Exit Sub
 Endif
 Exit Sub
Get.Config3:
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[TRAIN]" Then
       Do
          VarX=VarX+1
          If VarX>Options.Lines Then
             Return
          Endif
          Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
          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)))
             Select Case Lcase$(Var2$)
             Case "team.hit.monster"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option1$=Mid$(Var3$,2)
                      option1$=Left$(option1$,Len(option1$)-1)
                   Endif
                Endif
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
ErrorResume4y:
 Exit Sub
ErrorTrap4y:
 Resume ErrorResume4y
End Sub

Sub Monster.Died
 On Local Error Goto ErrorTrap4a
 Gosub Get.Config9
 Var$=Out3
 Var3$="killed a "+Var$
 If Instr("aeiou", Left$(Var$, 1)) Then
    Var3$="killed an "+Var$
 Endif
 If MessWorkRecord3.Monster.Permanent<True Then
    Var3$="killed the "+Var$
 Endif
 Out2=Lcase$(Rtrim$(UserRecord.CodeName))
 Out2=Out2+" just "+Var3$+"!"
 Call Send.Mess(8,SFalse,Room,Out2)
 Choice=MessWorkRecord3.Index
 Last.Command.Number=False
 Call Update.DayFile(Var3$,False,1)
 ' check npc
 If MessWorkRecord3.Monster.Permanent=-2 Then
    VarX=True
 Else
    VarX=False
 Endif
 ' override npc inventory
 If MessWorkRecord3.Monster.Permanent=-2 Then
    If Option1=0 Then Goto End.Drop.Inv
 Endif
 Graphics.Off=True
 Strng="On it you find "
 Carriage.Return=True
 Call IO.O
 Strng2=Nul
 Temp9=False
 For Temp2!=1! To Lof(MessWorkFile5)/MessWorkRecLen5
    Call Read.Record(MessWorkFile5,Temp2!)
    Temp3!=MessWorkRecord5.Index
    Temp7=SFalse
    If VarX Then
       If Temp3!=-Choice Then
          Temp7=True
       Endif
    Else
       If Temp3!=Choice Then
          Temp7=True
       Endif
    Endif
    If MessWorkRecord5.Room<>Room Then
       Temp7=False
    Endif
    If MessWorkRecord5.Monster<>Monster.Temp Then
       Temp7=False
    Endif
    If Temp7 Then
       Temp5!=MessWorkRecord5.Inv
       If Temp5!<SFalse Then
          Temp5!=Abs(Temp5!)
          If Temp5!>SFalse And Temp5!<=Lof(ObjectFile)/ObjectRecLen Then
             Call Read.Record(ObjectFile,Temp5!)
             Call Drop.Item.In.Room(Temp5!,False)
             Temp9=Temp9+1
             Call Convert.ANSI(True,VarQ,VarR)
             Carriage.Return=True
             Graphics.On=True
             Call IO.O
             Graphics.On=False
             If Len(Strng2) Then
                Carriage.Return=True
                Strng=Strng2
                Call IO.O
             Endif
             Strng=Rtrim$(ObjectRecord.ObjectName)
             Strng=Rtrim$(ObjectRecord.Prefix1)+Strng
             Strng2=", "
          Endif
       Else
          If Temp5!>SFalse And Temp5!<=Lof(TreasureFile)/TreasureRecLen Then
             Call Read.Record(TreasureFile,Temp5!)
             If TreasureRecord.Container Then
                Call Drop.Container.In.Room(Temp5!)
             Else
                Var1=MessWorkRecord5.Charges
                Call Drop.Inventory(Temp5!,Var1)
             Endif
             Temp9=Temp9+1
             Call Convert.ANSI(True,VarQ,VarR)
             Carriage.Return=True
             Graphics.On=True
             Call IO.O
             Graphics.On=False
             If Len(Strng2) Then
                Carriage.Return=True
                Strng=Strng2
                Call IO.O
             Endif
             Strng=Rtrim$(TreasureRecord.TreasureName)
             Strng=Rtrim$(TreasureRecord.Prefix1)+Strng
             Strng2=", "
          Endif
       Endif
       MessWorkRecord5.Index=SFalse
       MessWorkRecord5.IsAutomaton=False
       Call Write.Record(MessWorkFile5,Temp2!)
    Endif
 Next
 If Temp9=False Then
    Strng="nothing."
 Else
    If Temp9>1 Then
       Strng="and "+Strng
    Endif
 Endif
 Call Convert.ANSI(True,VarQ,VarR)
 Carriage.Return=True
 Graphics.On=True
 Call IO.O
 Graphics.On=False
 If Len(Strng2) Then
    Strng=Left$(Strng2,Len(Strng2)-2)+"."
 Else
    Strng="."
 Endif
 Call IO.O
End.Drop.Inv:
 Select Case MessWorkRecord3.Monster.Permanent
 Case -2 ' nonplayer
    Eat$=Nul
 Case True ' permanent monster
    Permanent.Killed=Permanent.Killed+1
    UserRecord.PermanentKilled=UserRecord.PermanentKilled+1
 Case False ' monster
    Monsters.Killed=Monsters.Killed+1
    UserRecord.MonstersKilled=UserRecord.MonstersKilled+1
    Call Read.Record(MonsterFile,Choice)
    If MonsterRecord.Buffer16>=999999! Then
       MonsterRecord.Buffer15=MonsterRecord.Buffer15+1! ' 1,000,000
       MonsterRecord.Buffer16=0!
    Else
       MonsterRecord.Buffer16=MonsterRecord.Buffer16+1!
    Endif
    Call Write.Record(MonsterFile,Choice)
 End Select
 Call Write.Record(UserFile,User.Index)
 Choice=MessWorkRecord3.Index
 If MessWorkRecord3.Monster.Permanent=True Then
    Call Read.Record(MonsterFile,Choice)
    MonsterRecord.Permanent=False
    Call Write.Record(MonsterFile,Choice)
 Endif
 Var!=UserRecord.Weapon(7).Index
 If Var! Then
    Temp2!=MessWorkRecord3.Monster.Level-UserRecord.Level
    If Temp2!>SFalse Then
       Call Read.Record(TreasureFile,Var!)
       If TreasureRecord.Proficiency=UserRecord.Proficiency Then
          Temp2=Temp2*10
       Else
          Temp2=Temp2*5
       Endif
       If Temp2>100 Then
          Temp2=100
       Endif
       Temp3=TreasureRecord.Proficiency
       If Temp2>UserRecord.Weapons(Temp3) Then
          UserRecord.Weapons(Temp3)=Temp2
       Endif
    Endif
 Endif
 Temp1#=MessWorkRecord3.Monster.Experience
 Temp2#=MessWorkRecord3.Monster.Gold
 Call Count.Last(VarZ,True)
 VarZ#=Cdbl(VarZ)
 Temp1#=Int(Temp1#/VarZ#)
 Temp2#=Int(Temp2#/VarZ#)
 Call Add.Experience(Temp1#,Temp2#)
 Call Add.Node.Exp(Temp1#,Temp2#,True)
 Call Add.Team.Exp(Temp1#,Temp2#,True)
 Call Remove.Monster

 ' nonplayers persist.
 If MessWorkRecord3.Monster.Permanent<True Then
    Strng="The "+Var$+" was resurrected!"
    Call IO.O
 Endif
 Exit Sub
Get.Config9:
 Option1=0
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[TRAIN]" Then
       Do
          VarX=VarX+1
          If VarX>Options.Lines Then
             Return
          Endif
          Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
          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)))
             Select Case Lcase$(Var2$)
             Case "allow.perm.inv"
                Select Case Lcase$(Var3$)
                Case "-1", "true", "on"
                   Option1=-1
                End Select
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
ErrorResume4a:
 Exit Sub
ErrorTrap4a:
 Resume ErrorResume4a
End Sub

Sub Remove.Monster
 On Local Error Goto ErrorTrap8
 Call Read.Record(MessWorkFile3,Monster.Temp)
 MessWorkRecord3.Room=SFalse
 MessWorkRecord3.AutoMode=False
 Call Write.Record(MessWorkFile3,Monster.Temp)
 Monster.Attacked=False
ErrorResume8:
 Exit Sub
ErrorTrap8:
 Resume ErrorResume8
End Sub

Sub Add.Experience(Var1#,Var2#)
 On Local Error Goto ErrorTrap27
 If Var1#>False Then
    VarX=False
    If Config2(93)=False Then
       If UserRecord.Experience>False Then
          VarX=True
       Endif
    Else
       Call Experience(Temp#)
       If UserRecord.Experience<Temp# Then
          VarX=True
       Endif
    Endif
    If VarX=False Then
       If UserRecord.Level<MaxInt Then
          Strng="You already have enough experience to train!"
          Call IO.O
       Endif
    Endif
    If VarX Then
       Select Case Var1#
       Case 1
          Strng="gained one experience point"
          Out2=".."
       Case 2 To 10
          Strng="gained "+Rtrim$(Numeral(Var1#))+" experience points"
          Out2="."
       Case Is>10
          Call Amount(Var1#,Var$)
          Strng="gained"+Var$+" experience points"
          Out2="!"
       End Select
       Strng2="You "+Strng+Out2
       Call Update.DayFile(Strng,False,2)
       Strng=Strng2
       Call IO.O
       If UserRecord.Level<MaxInt Then
          If Config2(93)=False Then
             UserRecord.Experience=UserRecord.Experience-Var1#
             Call Write.Record(UserFile,User.Index)
             If UserRecord.Experience<False Then
                UserRecord.Experience=False
                Strng="You now have zero experience to train!"
                Call IO.O
                Call Train
             Endif
          Else
             UserRecord.Experience=UserRecord.Experience+Var1#
             Call Write.Record(UserFile,User.Index)
             Call Experience(Temp#)
             If UserRecord.Experience>=Temp# Then
                Strng="You now have enough experience to train!"
                Call IO.O
                Call Train
             Endif
          Endif
       Endif
    Endif
 Endif
 If Var2#>DFalse Then
    Select Case Var2#
    Case 1 To 10
       Strng2=" "+Rtrim$(Numeral(Var2#))
    Case Else
       Call Amount(Var2#,Var$)
       Strng2=Var$
    End Select
    Strng="found"+Strng2+" gold"
    Call Update.DayFile(Strng,False,3)
    Strng="You found"+Strng2+" gold!"
    Call IO.O
    UserRecord.Gold=UserRecord.Gold+Var2#
 Endif
 Call Write.Record(UserFile,User.Index)
ErrorResume27:
 Exit Sub
ErrorTrap27:
 Resume ErrorResume27
End Sub

Sub Drop.Item.In.Room(Var1!,Var2)
 On Local Error Goto ErrTrap23b
 VarX!=Lof(RoomInvFile)/MessWorkRecLen6+1!
 MessWorkRecord6.Room=Room
 MessWorkRecord6.User=SFalse
 MessWorkRecord6.Index=-Abs(Var1!)
 MessWorkRecord6.Charges=Var2
 MessWorkRecord6.Plus=False
 Call Write.Record(RoomInvFile,VarX!)
 Call Add.List.Node(VarX!)
ErrResume23b:
 Exit Sub
ErrTrap23b:
 Resume ErrResume23b
End Sub

Sub Count.Last(Var,VarQ)
 On Local Error Goto ErrorTrap17a
 VarX=1
 For VarZ=False To MaxNodes
    If VarZ<>Node Then
       Call Read.Message.Record(MessWorkFile1,VarZ+1)
       Strng=Rtrim$(MessWorkRecord1.UserName)
       Call Valid.Name(Strng)
       If TempA Then
          If MessWorkRecord1.RoomNumber=Room Then
             Select Case VarQ
             Case -1
                If MessWorkRecord1.LastMonster=Monster.Attacked Then
                   VarX=VarX+1
                Endif
             Case 0
                If MessWorkRecord1.LastUser=User.Attacked Then
                   VarX=VarX+1
                Endif
             End Select
          Endif
       Endif
    Endif
 Next
 Call Count.Team.Members(Var4)
 Var=VarX+Var4
ErrorResume17a:
 Exit Sub
ErrorTrap17a:
 Resume ErrorResume17a
End Sub

Sub Count.Team.Members(Var4)
 On Local Error Goto ErrorTrap4z
 Var4=False
 If Config2(19)=0 Then
    Exit Sub
 Endif
 For User.Temp=1! To Lof(MessWorkFile4)/MessWorkRecLen4
    Call Read.Record(MessWorkFile4,User.Temp)
    Var5=False
    If MessWorkRecord4.Room=Room Then
       Call Read.Record(UserFile2,MessWorkRecord4.Index)
       For Var!=1! To Lof(TeamFile)/TeamRecLen
          Call Read.Record(TeamFile,Var!)
          If TeamRecord.Deleted=False Then
             For VarY=1 To MaxTeamMembers
                Var2!=TeamRecord.UserIndex(VarY)
                If Var2!=User.Index Then
                   For VarZ=1 To MaxTeamMembers
                      Var2!=TeamRecord.UserIndex(VarZ)
                      If Var2!=MessWorkRecord4.Index Then
                         If TeamRecord.Activated(VarZ) Then
                            Var4=Var4+1
                            Var5=True
                            Exit FOr
                         Endif
                      Endif
                   Next
                Endif
                If Var5 Then
                   Exit For
                Endif
             Next
          Endif
          If Var5 Then
             Exit For
          Endif
       Next
    Endif
 Next
ErrorResume4z:
 Exit Sub
ErrorTrap4z:
 Resume ErrorResume4z
End Sub

Sub Add.Node.Exp(Var1#,Var2#,VarQ)
 On Local Error Goto ErrorTrap17b
 Var1$=Str$(Var1#)+" "+Str$(Var2#)
 For VarZ=False To MaxNodes
    If VarZ<>Node Then
       Call Read.Message.Record(MessWorkFile1,VarZ+1)
       Strng=Rtrim$(MessWorkRecord1.UserName)
       Call Valid.Name(Strng)
       If TempA Then
          If MessWorkRecord1.RoomNumber=Room Then
             TempB!=MessWorkRecord1.UserIndex
             Select Case VarQ
             Case -1
                If MessWorkRecord1.LastMonster>SFalse And Monster.Attacked>SFalse Then
                   If MessWorkRecord1.LastMonster=Monster.Attacked Then
                      Call Send.Mess(27,TempB!,Room,Var1$)
                      MessWorkRecord1.LastMonster=SFalse
                      Call Write.Message.Record(MessWorkFile1,VarZ+1)
                      Call Read.Message.Record(MessWorkFile7,VarZ+1)
                      MessWorkRecord7.Flags4=MessWorkRecord7.Flags4 Or 2^5
                      Call Write.Message.Record(MessWorkFile7,VarZ+1)
                   Endif
                Endif
             Case 0
                If MessWorkRecord1.LastUser>SFalse And User.Attacked>SFalse Then
                   If MessWorkRecord1.LastUser=User.Attacked Then
                      Call Send.Mess(27,TempB!,Room,Var1$)
                      MessWorkRecord1.LastUser=SFalse
                      Call Write.Message.Record(MessWorkFile1,VarZ+1)
                      Call Read.Message.Record(MessWorkFile7,VarZ+1)
                      MessWorkRecord7.Flags4=MessWorkRecord7.Flags4 Or 2^6
                      Call Write.Message.Record(MessWorkFile7,VarZ+1)
                   Endif
                Endif
             End Select
          Endif
       Endif
    Endif
 Next
ErrorResume17b:
 Exit Sub
ErrorTrap17b:
 Resume ErrorResume17b
End Sub

Sub Add.Team.Exp(Var1#,Var2#,VarQ)
 On Local Error Goto ErrorTrap17c
 If Config2(19)=0 Then
    Exit Sub
 Endif
 For User.Temp=1! To Lof(MessWorkFile4)/MessWorkRecLen4
    Call Read.Record(MessWorkFile4,User.Temp)
    Var5=False
    If MessWorkRecord4.Room=Room Then
       Call Read.Record(UserFile2,MessWorkRecord4.Index)
       Out4=UserRecord2.CodeName
       Out4=Rtrim$(Out4)
       Out4=Lcase$(Out4)
       If Len(Out4) Then
          Mid$(Out4,1,1)=Ucase$(Mid$(Out4,1,1))
       Endif
       For Var!=1! To Lof(TeamFile)/TeamRecLen
          Call Read.Record(TeamFile,Var!)
          If TeamRecord.Deleted=False Then
             For VarY=1 To MaxTeamMembers
                Var2!=TeamRecord.UserIndex(VarY)
                If Var2!=User.Index Then
                   For VarZ=1 To MaxTeamMembers
                      Var2!=TeamRecord.UserIndex(VarZ)
                      If Var2!=MessWorkRecord4.Index Then
                         If TeamRecord.Activated(VarZ) Then
                            UserRecord2.MonstersKilled=UserRecord2.MonstersKilled+1
                            Call Write.Record(UserFile2,MessWorkRecord4.Index)
                            Var5=True
                            If Var1#>False Then
                               Select Case Var1#
                               Case 1
                                  Strng=" gained one experience point.."
                               Case 2 To 10
                                  Strng=" gained "+Rtrim$(Numeral(Var1#))+" experience points."
                               Case Is>10
                                  Call Amount(Var1#,Var$)
                                  Strng=" gained"+Var$+" experience points!"
                               End Select
                               Strng=Out4+Strng
                               Call IO.O
                               VarX=False
                               If Config2(93)=False Then
                                  If UserRecord2.Experience>False Then
                                     VarX=True
                                  Endif
                               Else
                                  Call Experience2(Temp#)
                                  If UserRecord2.Experience<Temp# Then
                                     VarX=True
                                  Endif
                               Endif
                               If Config2(93)=False Then
                                  UserRecord2.Experience=UserRecord2.Experience-Var1#
                                  If UserRecord2.Experience<False Then
                                     UserRecord2.Experience=False
                                     Call Train2
                                  Endif
                               Else
                                  UserRecord2.Experience=UserRecord2.Experience+Var1#
                                  Call Experience(Temp#)
                                  If UserRecord2.Experience>=Temp# Then
                                     Call Train2
                                  Endif
                               Endif
                            Endif
                            If Var2#>DFalse Then
                               Select Case Var2#
                               Case 1 To 10
                                  Strng=" "+Rtrim$(Numeral(Var2#))
                               Case Else
                                  Call Amount(Var2#,Var$)
                                  Strng=Var$
                               End Select
                               Strng=Out4+" found"+Strng+" gold!"
                               Call IO.O
                               UserRecord2.Gold=UserRecord2.Gold+Var2#
                            Endif
                            Call Write.Record(UserFile2,MessWorkRecord4.Index)
                            MessWorkRecord4.Exp=UserRecord2.Experience
                            Call Write.Record(MessWorkFile4,User.Temp)
                            Exit For
                         Endif
                      Endif
                   Next
                Endif
                If Var5 Then
                   Exit For
                Endif
             Next
          Endif
          If Var5 Then
             Exit For
          Endif
       Next
    Endif
 Next
ErrorResume17c:
 Exit Sub
ErrorTrap17c:
 Resume ErrorResume17c
End Sub

Sub Experience2(Var#)
 On Local Error Goto ErrTrap16x
 Var1#=Config2(92)+Config2(95)
 Var2#=2^Var1#
 If UserRecord2.Level<=Config2(95) Then
    Var#=2^(UserRecord2.Level+Config2(92))
 Else
    Var#=Var2#+(UserRecord2.Level-Config2(95))*Config1(32)
 Endif
ErrResume16x:
 Exit Sub
ErrTrap16x:
 Resume ErrResume16x
End Sub

Sub Clear.List.Node
 On Local Error Goto ErrorTrp32c
 MessWorkRecord6.User=SFalse
 MessWorkRecord6.Room=SFalse
 MessWorkRecord6.Index=SFalse
 MessWorkRecord6.Charges=False
 MessWorkRecord6.Plus=False
 MessWorkRecord6.Prev=SFalse
 MessWorkRecord6.Next=SFalse
 For Var=1 To 4
    MessWorkRecord6.Desc(Var)=0!
 Next
ErrorRsm32c:
 Exit Sub
ErrorTrp32c:
 Resume ErrorRsm32c
End Sub

Sub Delete.List.Node(VarZ!)
 On Local Error Goto ErrorTrp32b
 Call Read.Record(RoomFile,Room)
 If RoomRecord.First=VarZ! Then
    Call Read.Record(RoomInvFile,VarZ!)
    RoomRecord.First=MessWorkRecord6.Next
    Call Write.Record(RoomFile,Room)
    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,Room)
       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!)
       Call Read.Record(RoomInvFile,VarZ!)
    Endif
 Endif
ErrorRsm32b:
 Exit Sub
ErrorTrp32b:
 Resume ErrorRsm32b
End Sub

Sub Return.Room(VarX!)
 On Local Error Goto ErrorTrap51
 VarX!=SFalse
 If ObjectRecord.RoomLink1=Room And ObjectRecord.RoomLink2<>SFalse Then
    VarX!=ObjectRecord.RoomLink2
 Else
    If ObjectRecord.RoomLink2=Room And ObjectRecord.RoomLink1<>SFalse Then
       VarX!=ObjectRecord.RoomLink1
    Else
       If ObjectRecord.RoomLink1<>SFalse Then
          VarX!=ObjectRecord.RoomLink1
       Else
          If ObjectRecord.RoomLink2<>SFalse Then
             VarX!=ObjectRecord.RoomLink2
          Endif
       Endif
    Endif
 Endif
ErrorResume51:
 Exit Sub
ErrorTrap51:
 Resume ErrorResume51
End Sub

Sub Traps
 On Local Error Goto ErrorTrap42
 Gosub Get.Config7
 New.Room=False
 TempZ1=ObjectRecord.Trap
 If TempZ1>=1 And TempZ1<=5 Then
    If Len(option1$) Then
       Out2=option1$
       Call Equate(Temp#)
    Else
       Temp#=Rnd>.5
    Endif
    If Temp# Then
       Var2!=UserRecord.Weapon(4).Index
       If Var2! Then
          Call Read.Record(TreasureFile,Var2!)
          If TreasureRecord.RingType=4 Then
             Call Get.Ring.Hits(True,4)
             Exit Sub
          Endif
       Endif
       Var2!=UserRecord.Weapon(9).Index
       If Var2! Then
          Call Read.Record(TreasureFile,Var2!)
          If TreasureRecord.RingType=4 Then
             Call Get.Ring.Hits(False,4)
             Exit Sub
          Endif
       Endif
       If Node>False Then
          Out2=UserRecord.CodeName
          Out2=Rtrim$(Out2)
          Out2=Lcase$(Out2)
          Out2=Out2+" was just hit by a trap."
          Call Send.Mess(8,SFalse,Room,Out2)
       Endif
       Strng="It's trapped! "
       Select Case TempZ1
       Case 1
          Strng=Strng+"Poison needles!"
          Call IO.O
          UserRecord.Poison=True
       Case 2
          If ObjectRecord.Teleport<>Room Then
             VarX=False
             Var2!=UserRecord.Weapon(4).Index
             If Var2! Then
                Call Read.Record(TreasureFile,Var2!)
                If TreasureRecord.RingType=9 Then
                   VarX=True
                   Call Get.Ring.Hits(True,9)
                Endif
             Endif
             If VarX=False Then
                Var2!=UserRecord.Weapon(9).Index
                If Var2! Then
                   Call Read.Record(TreasureFile,Var2!)
                   If TreasureRecord.RingType=9 Then
                      VarX=True
                      Call Get.Ring.Hits(False,9)
                   Endif
                Endif
             Endif
             If VarX=False Then
                Strng=Strng+"Falling door!"
                Call IO.O
                Pass.Door=False
                Next.Room=ObjectRecord.Teleport
                Call Teleport
                Call Enter.Room
             Endif
          Endif
       Case 3
          Strng=Strng+"Deadly spears!"
          Call IO.O
          Prefix2=Nul
          Strng="You are hit for"
          Out3="some deadly spears"
          Temp2=Cint(ObjectRecord.Teleport)
          If Temp2 Then
             Call Hit.Player(Temp2)
          Endif
       Case 4
          Strng=Strng+"Crushing ceiling!"
          Call IO.O
          UserRecord.Level=UserRecord.Level-1
          Call New.Stats
          UserRecord.Experience=False
          If Config2(93)=False Then
             Call Experience(Temp#)
             UserRecord.Experience=Temp#
          Endif
          If UserRecord.Level<=False Then
             UserRecord.Level=1
             Message1="You were just killed by a trap!"
             Strng="was killed by a trap"
             Call Update.DayFile(Strng,False,1)
             Call Player.Died
          Endif
       Case 5
          Strng=Strng+"Blade barrier!"
          Call IO.O
          Call Get.Weapon.Hits
       End Select
    Endif
 Endif
 Exit Sub
Get.Config7:
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[TRAIN]" Then
       Do
          VarX=VarX+1
          If VarX>Options.Lines Then
             Return
          Endif
          Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
          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)))
             Select Case Lcase$(Var2$)
             Case "trap.equation"
                If Left$(Var3$,1)=Chr$(34) Then
                   If Right$(Var3$,1)=Chr$(34) Then
                      option1$=Mid$(Var3$,2)
                      option1$=Left$(option1$,Len(option1$)-1)
                   Endif
                Endif
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
ErrorResume42:
 Exit Sub
ErrorTrap42:
 Resume ErrorResume42
End Sub

Sub Get.Direction
 On Local Error Goto ErrorTrap46
 For TempA=1 To MaxDirections
    Out3=Direction(TempA)
    Out3=Rtrim$(Out3)
    Out3=Ucase$(Out3)
    If Left$(Out3,Len(User.Command))=User.Command Then
       Exit Sub
    Endif
 Next
 Call Find.Link(User.Command)
 If Temp3 Then
    TempA=Temp3
 Else
    TempA=False
 Endif
ErrorResume46:
 Exit Sub
ErrorTrap46:
 Resume ErrorResume46
End Sub

Sub Find.Link(Var1$)
 On Local Error Goto ErrorTrap49
 Select Case Ucase$(Var1$)
 Case "N"
    Temp3=1
 Case "E"
    Temp3=2
 Case "S"
    Temp3=3
 Case "W"
    Temp3=4
 Case "NE"
    Temp3=5
 Case "SE"
    Temp3=6
 Case "SW"
    Temp3=7
 Case "NW"
    Temp3=8
 Case "U"
    Temp3=9
 Case "D"
    Temp3=10
 Case "I"
    Temp3=11
 Case "O"
    Temp3=12
 Case "1"
    Temp3=13
 Case "2"
    Temp3=14
 Case Else
    Temp3=False
 End Select
ErrorResume49:
 Exit Sub
ErrorTrap49:
 Resume ErrorResume49
End Sub

Sub Amount(Var#,Var$)
 If Instr(Str$(Var#),"D") Then
    Var$=Str$(Var#)
 Else
    Var$=" "+Form$(Var#)
 Endif
End Sub
