 Rem File: Cmd073.bas
 Rem Sub: Launch.Object
 Rem $Include: 'dndbbs.inc'
 On Error Goto Main.Error
 If Chained<>-2 Then
    Color 15,0
    Print "DNDBBS Command 073 -- Launch.Object."
    Color 7,0
    End
 Endif
 Call Launch.Object
Main.Resume:
 Chain DND.Path+"DNDBBS.EXE"
 End
Main.Error:
 Resume Main.Resume

Sub Launch.Object
 On Local Error Goto ErrorTrp62
 Gosub Get.Config
 Call Parse
 If Parser Then
    Call Numeric
 Endif
 Temp4=1
 Call Check.Room.Items
 If Temp7!<SFalse Then
    Strng="You can't launch that!"
    Call IO.O
    Exit Sub
 Endif
 If Temp7!=SFalse Then
    Temp4=False
    Call Num
    Call Check.User.Items
    If Temp7!<=SFalse Then
       Strng="You can't launch that!"
       Call IO.O
       Exit Sub
    Endif
 Endif
 If TreasureRecord.Launchable=False Then
    Strng="That's not a launchable device!"
    Call IO.O
    Exit Sub
 Endif
 TempZ=False
 TempI=Temp4
 TempJ!=Temp5!
 TempE=Temp6
 TempF=False
 TempK!=TreasureRecord.LaunchLoads
 If TempK!>False And TempK!<=Lof(TreasureFile)/Len(TreasureRecord) Then
    Call Read.Record(TreasureFile,TempK!)
    TempF=TreasureRecord.Charges
 Endif
 Call Read.Record(TreasureFile,Temp7!)
 If Temp6=False Then
    Strng="You can't, it's not loaded."
    Call IO.O
    Exit Sub
 Endif
 If TempE>Option1 Then
    TempE=Option1
 Endif
 TempK=False
 TempZ!=Room
 Out5=Lcase$(Rtrim$(TreasureRecord.ShortName))
 User.Command=Parsed.Command2
 Parsed.Command1=User.Command
 ' launch at room object
 Call Numeric
 VarZ=Parse.Temp
 Call Check.Room.Items
 If Temp7!<SFalse Then
    Call Drop.Inventory(TempK!,TempF)
    TempK=1
    Var!=Abs(Temp7!)
    Call Read.Record(ObjectFile,Var!)
    If ObjectRecord.JailTrap Then
       Call Jail
    Else
       If ObjectRecord.DoorLock=2 Then
          Out3=ObjectRecord.ShortName
          Out3=Rtrim$(Out3)
          Out3=Lcase$(Out3)
          Strng="You launch the "+Out5+" at the "+Out3+"!"
          Call IO.O
          TempA=False
          If Len(option1$) Then
             Out2=option1$
             Call Equate(Temp#)
          Else
             Temp#=Rnd>.66
          Endif
          If Temp# Then
             TempA=True
             ObjectRecord.DoorLock=1
             ObjectRecord.Closed=False
             Call Write.Record(ObjectFile,Var!)
          Endif
          If TempA=False Then
             Strng="You didn't smash open anything!"
          Else
             Strng="You smashed open a lock!"
          Endif
       Else
          Strng="Nothing happened!"
       Endif
       Call IO.O
    Endif
 Else
    ' launch in direction
    Call Get.Direction
    If TempA Then
       Strng2=Direction(TempA)
    Endif
    If TempA=False Then
       ' custom room direction#1
       Call Read.Record(RoomFile,Room)
       Out3=Rtrim$(RoomRecord.Custom1)
       If Out3=String$(12,Chr$(0)) Then
          Out3=Nul
       Endif
       If Len(Out3) Then
          If Ucase$(Out3)=Parsed.Command1 Then
             TempA=13
             Strng2=Lcase$(Out3)
          Endif
       Endif
    Endif
    If TempA=False Then
       ' custom room direction#2
       Call Read.Record(RoomFile,Room)
       Out3=Rtrim$(RoomRecord.Custom2)
       If Out3=String$(12,Chr$(0)) Then
          Out3=Nul
       Endif
       If Len(Out3) Then
          If Ucase$(Out3)=Parsed.Command1 Then
             TempA=14
             Strng2=Lcase$(Out3)
          Endif
       Endif
    Endif
    If TempA=False Then
       ' custom room direction file
       Call Find.Custom2(Var$,Var!)
       If TempA Then
          Next.Room=Var!
          Strng2=Var$
       Endif
    Endif
    If TempA Then
       If TempA<=14 Then
          Next.Room=RoomRecord.Direct(TempA)
       Endif
       If Next.Room=SFalse Then
          Strng="You can't launch at that!"
          Call IO.O
          Exit Sub
       Endif
       TempZ=True
       Out3=Strng2
       Out3=Rtrim$(Out3)
       Out3=Lcase$(Out3)
       Strng="You launch the "+Out5+" "+Out3+"!"
       Call IO.O
       For TempQ=1 To TempE
          Graphics.Off=False
          If TempQ<=10 Then
             Out2=Rtrim$(Numeral(TempQ))
          Else
             Out2=Form$(Cdbl(TempQ))
          Endif
          Strng="For launch "+Out2+";"
          Call IO.O
          TempK=TempK+1
          Graphics.Off=True
          Strng="The device launchs: "
          Carriage.Return=True
          Call IO.O
          Strng=Out3+", "
          Carriage.Return=True
          Call IO.O
          TempA=False
          TempB=1
          Call Chain.Rooms(Next.Room,Room)
          Strng="and stopped!"
          Call IO.O
          Room=TempC!
          Call Read.Record(RoomFile,Room)
          Call Drop.Inventory(TempK!,TempF)
          Room=TempZ!
          Call Read.Record(RoomFile,Room)
       Next
       If TempA=False Then
          Strng="You didn't smash anything!"
       Else
          Strng="You smashed open "
          If TempA<=10 Then
             Strng=Strng+Rtrim$(Numeral(TempA))
          Else
             Strng=Strng+Form$(Cdbl(TempA))
          Endif
          If TempA=1 Then
             Strng=Strng+" lock.."
          Else
             Strng=Strng+" locks!"
          Endif
       Endif
       Call IO.O
       Graphics.Off=False
    Else
       ' launch at monster
       Strng="You launch the "+Out5+"!"
       Call IO.O
       Multiplier=TreasureRecord.Plus
       Graphics.Off=True
       Var$=Parsed.Command1
       For TempQ=1 To TempE
          Parse.Temp=VarZ
          If TempQ<=10 Then
             Out2=Rtrim$(Numeral(TempQ))
          Else
             Out2=Form$(Cdbl(TempQ))
          Endif
          Strng="For launch "+Out2+";"
          Call IO.O
          Parsed.Command1=Var$
          Last.Monster=Var$
          Call Attack.Monster(VarZ1)
          If VarZ1=0 Then
             Exit For
          Endif
          TempK=TempK+1
          Call Read.Record(RoomFile,Room)
          Call Drop.Inventory(TempK!,TempF)
          If TempZ!<>Room Then
             Exit For
          Endif
       Next
       Graphics.Off=False
    Endif
 Endif
 Call Read.Record(RoomFile,TempZ!)
 Select Case TempI
 Case 0
    Call Read.Record(MessWorkFile6,TempJ!)
    MessWorkRecord6.Charges=MessWorkRecord6.Charges-TempK
    If MessWorkRecord6.Charges<False Then
       MessWorkRecord6.Charges=False
    Endif
    Call Write.Record(MessWorkFile6,TempJ!)
 Case 1
    Call Read.Record(RoomInvFile,TempJ!)
    MessWorkRecord6.Charges=MessWorkRecord6.Charges-TempK
    If MessWorkRecord6.Charges<False Then
       MessWorkRecord6.Charges=False
    Endif
    Call Write.Record(RoomInvFile,TempJ!)
 End Select
 Call Read.Record(RoomFile,Room)
 Exit Sub
Get.Config:
 Option1=10
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD073]" 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 "maximum.launch.items"
                If Int(Val(Var3$))>=1 And Int(Val(Var3$))<=32767 Then
                   Option1=Int(Val(Var3$))
                Endif
             Case "smash.lock.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
ErrorRsm62:
 Exit Sub
ErrorTrp62:
 Resume ErrorRsm62
End Sub

Sub Chain.Rooms(Chain.Room!,Previous.Room!)
 On Local Error Goto ErrorTrp63
 Gosub Get.Config2
 TempC!=Chain.Room!
 Call Read.Record(RoomFile,Chain.Room!)
 Temp!=RoomRecord.First
 If Temp! Then
    Do While Lost.Carrier=False
       Call Read.Record(RoomInvFile,Temp!)
       If MessWorkRecord6.Room=SFalse Then
          Exit Do
       Endif
       Var!=MessWorkRecord6.Index
       If Var!<SFalse Then
          Var!=Abs(Var!)
          Call Read.Record(ObjectFile,Var!)
          If ObjectRecord.DoorLock=2 Then
             If Len(option1$) Then
                Out2=option1$
                Call Equate(Temp#)
             Else
                Temp#=Rnd>.66
             Endif
             If Temp# Then
                TempA=TempA+1
                ObjectRecord.DoorLock=1
                ObjectRecord.Closed=False
                Call Write.Record(ObjectFile,Var!)
             Endif
          Endif
       Endif
       Temp!=MessWorkRecord6.Next
       If Temp!=SFalse Then
          Exit Do
       Endif
    Loop
 Endif
 VarZ1=Config2(143)
 If VarZ1>False And VarZ<=100 Then
    VarZ2!=Csng(VarZ1)/100!
 Else
    VarZ2!=.5!
 Endif
 VarZ3=Config2(144)
 If VarZ3<=False Then
    VarZ3=5
 Endif
 If VarZ3>10 Then
    VarZ3=10
 Endif
 For Temp.Direction=1 to MaxDirections
    Temp.Room!=RoomRecord.Direct(Temp.Direction)
    If Temp.Room! Then
       If Temp.Room!<>Previous.Room! Then
          If Rnd<VarZ2! Then
             If TempB<VarZ3 Then
                Carriage.Return=True
                Strng=Direction(Temp.Direction)
                Strng=Rtrim$(Strng)+", "
                Call IO.O
                TempB=TempB+1
                Call Chain.Rooms(Temp.Room!,Chain.Room!)
                Call Read.Record(RoomFile,Chain.Room!)
                Exit Sub
             Endif
          Endif
       Endif
    Endif
 Next
 Temp.Room!=RoomRecord.Direct(13)
 If Temp.Room! Then
    If Temp.Room!<>Previous.Room! Then
       If Rnd<VarZ2! Then
          If TempB<VarZ3 Then
             Carriage.Return=True
             Strng=Rtrim$(RoomRecord.Custom1)
             If Strng=String$(12,Chr$(0)) Then
                Strng=Nul
             Endif
             If Len(Strng) Then
                Strng=Lcase$(Rtrim$(Strng))+", "
                Call IO.O
                TempB=TempB+1
                Call Chain.Rooms(Temp.Room!,Chain.Room!)
                Call Read.Record(RoomFile,Chain.Room!)
                Exit Sub
             Endif
          Endif
       Endif
    Endif
 Endif
 Temp.Room!=RoomRecord.Direct(14)
 If Temp.Room! Then
    If Temp.Room!<>Previous.Room! Then
       If Rnd<VarZ2! Then
          If TempB<VarZ3 Then
             Carriage.Return=True
             Strng=Rtrim$(RoomRecord.Custom2)
             If Strng=String$(12,Chr$(0)) Then
                Strng=Nul
             Endif
             If Len(Strng) Then
                Strng=Lcase$(Rtrim$(Strng))+", "
                Call IO.O
                TempB=TempB+1
                Call Chain.Rooms(Temp.Room!,Chain.Room!)
                Call Read.Record(RoomFile,Chain.Room!)
                Exit Sub
             Endif
          Endif
       Endif
    Endif
 Endif
 Exit Sub
 ' find custom room direction from file
 Call Find.Custom3(VarX!,Previous.Room!,VarZ2!,VarZ3)
 If VarX! Then ' next room
    Temp.Room!=VarX!
    If Temp.Room!<>Previous.Room! Then
       Carriage.Return=True
       Call IO.O
       TempB=TempB+1
       Call Chain.Rooms(Temp.Room!,Chain.Room!)
       Call Read.Record(RoomFile,Chain.Room!)
    Endif
 Endif
 Exit Sub
Get.Config2:
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD073]" 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 "smash.lock.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
ErrorRsm63:
 Exit Sub
ErrorTrp63:
 Resume ErrorRsm63
End Sub

Sub Find.Custom2(Var$,Var!)
 On Local Error Goto Err.Trp19a
 TampA=False
 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
       Input #TempFile1,Var1$,Var1!,Var2!,X,Y
       Var1$=Ucase$(Left$(Var1$,12))
       If Len(Var1$) Then
          If Var1$=Ucase$(Parsed.Command1) Then
             If Var1!=Room Then
                TempA=15
                Var!=Var2!
                Var$=Var1$
                Exit Do
             Endif
          Endif
       Endif
    Loop
 Endif
Err.Rsm19a:
 Exit Sub
Err.Trp19a:
 Resume Err.Rsm19a
End Sub

Sub Find.Custom3(VarZ!,VarX!,VarZ2!,VarZ3)
 On Local Error Goto Err.Trp19b
 VarZ!=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
       Input #TempFile1,Var1$,Var1!,Var2!,X,Y
       Var1$=Rtrim$(Left$(Var1$,12))
       If Len(Var1$) Then
          If Var1!=VarX! Then
             If Var2!>0! Then
                If Var2!<>VarX! Then
                   If Rnd<VarZ2! Then
                      If TempB<VarZ3 Then
                         VarZ!=Var2!
                         Strng=Lcase$(Var1$)
                         If debug.mode Then
                            Strng=Strng+"("+ltrim$(str$(var1!))+"-"+ltrim$(str$(varx!))+")"
                         Endif
                         Strng=Lcase$(Rtrim$(Strng))+", "
                         Exit Do
                      Endif
                   Endif
                Endif
             Endif
          Endif
       Endif
    Loop
 Endif
Err.Rsm19b:
 Exit Sub
Err.Trp19b:
 Resume Err.Rsm19b
End Sub

