 Rem File: Cmd051.bas
 Rem Sub: Enter.Object
 Rem $Include: 'dndbbs.inc'
 On Error Goto Main.Error
 If Chained<>-2 Then
    Color 15,0
    Print "DNDBBS Command 051 -- Enter.Object."
    Color 7,0
    End
 Endif

 ' store custom directions
 Var!=Room
 Var1$=RoomRecord.Custom1
 Var1!=RoomRecord.Direct(13)
 Var2$=RoomRecord.Custom2
 Var2!=RoomRecord.Direct(14)

 ' go.direction
 Call Enter.Object

 ' restore custom directions
 Call Read.Record(RoomFile,Var!)
 RoomRecord.Custom1=Var1$
 RoomRecord.Direct(13)=Var1!
 RoomRecord.Custom2=Var2$
 RoomRecord.Direct(14)=Var2!
 Call Write.Record(RoomFile,Var!)

 ' restore current room
 Call Read.Record(RoomFile,Room)
Main.Resume:
 Chain DND.Path+"DNDBBS.EXE"
 End
Main.Error:
 Resume Main.Resume

Sub Enter.Object
 On Local Error Goto ErrorTrp61
 User.Command=Parsed.Command1
 Call Read.Record(RoomFile,Room)
 ' custom direction from datafile
 Call Find.Custom2(VarX,VarZ,Var0!)
 If VarX Then
    If Sysop Or Normal.User=0 Or Debug.Mode Then
       Eat$=""
    Else
       If UserRecord.Level<VarZ Then
          Strng="Your level does not allow entrance to that room."
          Call IO.O
          Exit Sub
       Endif
    Endif
    RoomRecord.Custom1=User.Command
    RoomRecord.Direct(13)=Var0!
 Endif
 ' custom direction
 Var$=Rtrim$(RoomRecord.Custom1)
 If Var$=String$(12,Chr$(0)) Then
    Var$=Nul
 Endif
 If Len(Var$) Then
    If Ucase$(Var$)=Ucase$(User.Command) Then
       If RoomRecord.Direct(13)>SFalse Then
          TempA=13
          Call Verify.Room
          If New.Room Then
             Graphics.Off=False
             Strng="You go "+Lcase$(Var$)+"."
             Call IO.O
             Action.Recurse=0
             Call Enter.Room
          Endif
          If New.Room Then
             Call Enter.New.Room
          Endif
          Exit Sub
       Endif
    Endif
 Endif
 Var$=Rtrim$(RoomRecord.Custom2)
 If Var$=String$(12,Chr$(0)) Then
    Var$=Nul
 Endif
 If Len(Var$) Then
    If Ucase$(Var$)=Ucase$(User.Command) Then
       If RoomRecord.Direct(14)>SFalse Then
          TempA=14
          Call Verify.Room
          If New.Room Then
             Graphics.Off=False
             Strng="You go "+Lcase$(Var$)+"."
             Call IO.O
             Action.Recurse=0
             Call Enter.Room
          Endif
          If New.Room Then
             Call Enter.New.Room
          Endif
          Exit Sub
       Endif
    Endif
 Endif
 Call Get.Direction
 If TempA Then
    If Parse.Temp<=False Then
       Var3=1
    Else
       Var3=Parse.Temp
    Endif
    If Var3>16 Then
       Var3=16
    Endif
    Var1=TempA
    For Var2=1 To Var3
       TempA=Var1
       Call Verify.Room
       If New.Room Then
          Graphics.Off=False
          Strng="You go "+Rtrim$(Direction(TempA))+"."
          Call IO.O
          Action.Recurse=0
          Call Enter.Room
       Endif
       If New.Room Then
          Call Enter.New.Room
       Else
          Exit For
       Endif
    Next
    Exit Sub
 Endif
 Call Parse
 If Parser Then
    Call Numeric
 Endif
 Call Check.Room.Items
 If Temp7!>SFalse Then
    If TreasureRecord.Vehicle Then
       Call Enter.Vehicle
       Exit Sub
    Endif
 Endif
 If Temp7!=SFalse Then
    Call Num
    Call Check.User.Items
 Endif
 If Temp7!>=SFalse Then
    Strng="You can't go there!"
    Call IO.O
    Exit Sub
 Endif
 If ObjectRecord.JailTrap Then
    Strng="Trapped portal!"
    Call IO.O
    Exit Sub
 Endif
 Temp7!=Abs(Temp7!)
 Call Return.Room(Var!)
 If Var!=SFalse Then
    Strng="You can't go there!"
    Call IO.O
    Exit Sub
 Endif
 Call Restrict2(13) ' Go portal
 If TempB Then
    Strng="Your level does not allow entrance to that room!"
    Call IO.O
    Exit Sub
 Endif
 VarX=0
 If ObjectRecord.Doorlock=2 Then
    If Pass.Door=False Then
       If Sysop Then
          VarX=-1
       Else
          Strng="You can't, it's locked!"
          Call IO.O
          Exit Sub
       Endif
    Endif
 Endif
 If ObjectRecord.Closed Then
    If Pass.Door=False Then
       If Sysop Then
          VarX=-1
       Else
          Strng="You can't, it's closed!"
          Call IO.O
          Exit Sub
       Endif
    Endif
 Endif
 If VarX Then
    Strng="You bypass its lock!"
    Call IO.O
 Endif
 If Sysop=False Then
    Strng2=Rtrim$(ObjectRecord.PortalPassword)
    If Len(Strng2) Then
       Strng="Enter portal password: "
       Hidden=True
       Call IO.I
       Hidden=False
       Out2=Rtrim$(Ltrim$(Ucase$(Out2)))
       Call Crypto(Strng2)
       If Strng2<>Out2 Then
          Strng="Incorrect portal password.."
          Call IO.O
          Exit Sub
       Endif
    Endif
 Endif
 If ObjectRecord.Relocks Then
    ObjectRecord.DoorLock=2
    ObjectRecord.Closed=True
    Call Write.Record(ObjectFile,Temp7!)
 Endif
 Strng=Rtrim$(ObjectRecord.ShortDesc)
 Var=True
 If Strng=String$(80,0) Then
    Var=False
 Endif
 If Var Then
    Strng=Rtrim$(Strng)
    If Strng<>Nul Then
       Call Convert.ANSI(True,VarQ,VarR)
       Graphics.On=True
       Call IO.O
       Graphics.On=False
    Endif
 Endif
 If ObjectRecord.Trap Then
    Call Traps
    If New.Room Then
       Exit Sub
    Endif
 Endif
 Pass.Door=False
 Next.Room=Var!
 If Node>False Then
    Out2=Lcase$(Rtrim$(UserRecord.CodeName))
    Out2=Out2+" just went to the "
    Strng=ObjectRecord.ShortName
    Strng=Rtrim$(Strng)
    Strng=Lcase$(Strng)
    Out2=Out2+Strng+"."
    Call Send.Mess(8,SFalse,Room,Out2)
 Endif
 Action.Recurse=0
 Call Enter.Room
ErrorRsm61:
 Exit Sub
ErrorTrp61:
 Resume ErrorRsm61
End Sub
 
Sub Find.Custom2(Var,Var2,Var0!)
 On Local Error Goto Err.Trp19a
 Var=False
 Line1=0
 Filename=DND.Path+"custom.dat"
 If Dir$(Filename)<>"" Then
    Close #TempFile1
    Open Filename For Input Shared As #TempFile1
    Do
       If Eof(TempFile1) Then Exit Do
       Line1=Line1+1
       Input #TempFile1,Var1$,Var1!,Var2!,X,Y
       Var1$=Ucase$(Left$(Var1$,12))
       If Len(Var1$) Then
          If Var1$=Ucase$(User.Command) Then
             If Var1!=Room Then
                Var=True
                Var0!=Var2!
                Var2=Y
                Exit Do
             Endif
          Endif
       Endif
    Loop
 Endif
Err.Rsm19a:
 Exit Sub
Err.Trp19a:
 If Debug.Mode Then
    Strng="Error in " + Ucase$(Filename) + " in line"+Str$(Line1)+"."
    Call IO.O
 Endif
 Resume Err.Rsm19a
End Sub

Sub Enter.Vehicle
 On Local Error Goto Error.Trap12
 Out3=TreasureRecord.ShortName
 Out3=Rtrim$(Out3)
 Out3=Lcase$(Out3)
 If Temp6=False Then
    Strng="The "+Out3+" is damaged!"
    Call IO.O
    Exit Sub
 Endif
 If MessWorkRecord6.User<>SFalse Then
    If MessWorkRecord6.User=User.Index Then
       Strng="You are already using the "+Out3+"!"
       Call IO.O
       Exit Sub
    Endif
    Var=TreasureRecord.Occupants
    If Var>False Then
       For Var2=1 To Var
          If MessWorkRecord6.Temp(Var2)=User.Index Then
             Strng="You are already using the "+Out3+"!"
             Call IO.O
             Exit Sub
          Endif
       Next
    Endif
 Endif
 If MessWorkRecord6.User=SFalse Then
    If Vehicle1 Then
       Call Pack.Vehicles
    Endif
    Call Read.Record(RoomInvFile,Temp5!)
    MessWorkRecord6.User=User.Index
    Call Write.Record(RoomInvFile,Temp5!)
    Vehicle1=Temp5!
    Vehicle2=0
    Vehicle3=Temp7!
    Vehicle4=TreasureRecord.VehicleType
    Strng="You enter the "+Out3+"."
    Call IO.O
    Exit Sub
 Endif
 If Var=False Then
    Strng="The vehicle has no occupancy!"
    Call IO.O
    Exit Sub
 Endif
 For Var2=1 To Var
    If MessWorkRecord6.Temp(Var2)=SFalse Then
       If Vehicle1 Then
          Call Pack.Vehicles
       Endif
       Call Read.Record(RoomInvFile,Temp5!)
       MessWorkRecord6.Temp(Var2)=User.Index
       Call Write.Record(RoomInvFile,Temp5!)
       Vehicle1=Temp5!
       Vehicle2=Var2
       Vehicle3=Temp7!
       Vehicle4=TreasureRecord.VehicleType
       Strng="You enter the "+Out3+"."
       Call IO.O
       Exit Sub
    Endif
 Next
 Strng="The "+Out3+" is in use."
 Call IO.O
Error.Resume12:
 Exit Sub
Error.Trap12:
 Resume Error.Resume12
End Sub

Sub Verify.Room
 On Local Error Goto ErrorTrp59
 New.Room=False
 Next.Room=RoomRecord.Direct(TempA)
 If Next.Room=SFalse Then
    If Normal.User Then
       Strng="You can't go in that direction!"
       Call IO.O
    Else
       Call Add.Room(Var1)
       If Var1=False Then
          Strng="Room not added."
          Call IO.O
       Endif
    Endif
    Exit Sub
 Endif
 If UserRecord.ClassType<Lady Then
    For Temp5!=1! To Lof(MessWorkFile3)/MessWorkRecLen3
       Call Read.Record(MessWorkFile3,Temp5!)
       If MessWorkRecord3.Room=Room Then
          If MessWorkRecord3.Monster.Block Then
             If Rnd<(MessWorkRecord3.Monster.BlockPercent/100) Then
                Out2=MessWorkRecord3.Monster.MonsterName
                Out2=Rtrim$(Out2)
                Strng="The "+Out2+" blocks your way!"
                Call IO.O
                Exit Sub
             Endif
          Endif
       Endif
    Next
 Endif
 If TempA<13 Then
    Call Restrict2(TempA)
    If TempB Then
       Strng="Your level does not allow entrance to that room!"
       Call IO.O
       Exit Sub
    Endif
 Endif
 Call Restrict.Room.Type
 If TempB Then
    Select Case Entry.Command
    Case Fly
       Strng="fly"
    Case Swim
       Strng="swim"
    Case Else
       Strng="walk"
    End Select
    Strng="You can't "+Strng+" in that direction!"
    Call IO.O
    If Sysop Then
       Strng="Go in that direction anyway(y/n)? "
       No.Input.Out="Y"
       Call IO.I
       If Yes Then
          Eat$=Nul
       Else
          Exit Sub
       Endif
    Endif
    Exit Sub
 Endif
 If Node>False Then
    Out2=UserRecord.CodeName
    Out2=Lcase$(Out2)
    Out2=Rtrim$(Out2)
    Out2=Out2+" just went "
    Select Case TempA
    Case 1 To 12
       Strng=Rtrim$(Direction(TempA))
    Case 13
       Strng=Lcase$(Rtrim$(RoomRecord.Custom1))
    Case 14
       Strng=Lcase$(Rtrim$(RoomRecord.Custom2))
    Case Else
       Strng="somewhere"
    End Select
    Strng=Rtrim$(Strng)
    Out2=Out2+Strng+"."
    Call Send.Mess(8,SFalse,Room,Out2)
 Endif
 New.Room=True
ErrorRsm59:
 Exit Sub
ErrorTrp59:
 Resume ErrorRsm59
End Sub

Sub Restrict.Room.Type
 On Local Error Goto ErrorTrp60
 Call Read.Record(RoomFile,Next.Room)
 TempB=False
 Var2!=RoomRecord.Action
 If Var2!>SFalse And Var2!<=Lof(ActionFile)/ActionRecLen Then
    Call Read.Record(ActionFile,Var2!)
    If ActionRecord.Attribute2<>Air Then
       If Entry.Command=Fly Then
          TempB=True
       Endif
    Endif
    If ActionRecord.Attribute2=Air Then
       If Entry.Command<>Fly Then
          TempB=True
       Endif
    Endif
    If ActionRecord.Attribute2<>Water Then
       If Entry.Command=Swim Then
          TempB=True
       Endif
    Endif
    If ActionRecord.Attribute2=Water Then
       If Entry.Command<>Swim Then
          TempB=True
       Endif
    Endif
 Else
    If Entry.Command=Fly Or Entry.Command=Swim Then
       TempB=True
    Endif
 Endif
 Call Read.Record(RoomFile,Room)
ErrorRsm60:
 Exit Sub
ErrorTrp60:
 Resume ErrorRsm60
End Sub
