@q
@program vsys-@vrecycle
1 99999 d
i
 
( vsys-@vrecycle    v1.0    Jessy @ FurryMUCK    4/00
  
  Part of the vsys vehicle system, this program handles vehicle 
  recycling.
   
  INSTALLATION:
  
  Port the program, set it Wizard and Link_OK. Create a global action
  with a name such as '@vrecycle;@vrec', and link it to the program. 
  Type '<action name> #install'.
  
  Vsys-@vrecycle requires lib-vsys. See the header comment of lib-vsys
  for more complete documentation of the vehicle system.
  
  Vsys-@vrecycle may be freely ported. Please comment any changes.
)
  
$include $lib/vsys
 
$define Tell me @ swap notify $enddef
 
lvar ourRoom
lvar ourString
lvar ourVehicle
 
: DoInit  (  --  )              (* ensure program is W and registered *)
 
  LibInit
  prog "W" flag? if
    #0 "_reg/vsys/vrecycle-prog" prog setprop
    #0 "_reg/vsys/vrecycle-com"  trig setprop
  else
    prog name " must be set Wizard." strcat me @ swap notify
    pid kill
  then
;
  
: DoInstall  (  --  )                  (* doesn't really do anything *)
  
  DoInit
  ">>  $prog installed." prog name "$prog" subst Tell
;
 
: DoHelp
  
  " " Tell
  prog name " (#" strcat prog intostr strcat ")" strcat Tell " " Tell
  
  "This program recycles vsys vehicles and all rooms associated with "
  "them." strcat " " Tell
  
  "  $com <vehicle obj> ......... Recycle <vehicle> and its rooms"
  command @ "$com" subst Tell " " Tell
  
  "You must be a wizard or the owner of the vehicle to use this command."
  Tell " " Tell 
   
  "For complete information on the vehicle system, type '@view $lib/vsys' "
  "(long)." strcat Tell
;
 
: DoRecContainedRooms  ( d --  ) (* recycle all rooms in d, recursive *)
  
  contents
  begin
    dup while
    dup next swap
    dup room? if
      dup contents if 
        dup DoRecContainedRooms
      then
      recycle
    else
      pop
    then
  repeat
  pop
;
 
: DoVrecycle  (  --  )     (* recycle vehicle ourString and its rooms *)
  
  ourString @ if                                      (* find vehicle *)
    ourString @ match
    dup #-1 dbcmp if
      ">>  I don't see that here." Tell exit
    then
    dup #-2 dbcmp if
      ">>  Ambiguous. I don't know which one you mean!" Tell exit
    then
    dup #-3 dbcmp if
      ">>  I don't see that here." Tell exit
    then
    ourVehicle !
    me @ ourVehicle @ controls if                 (* check permission *)
      ourVehicle @ GetEnvForVeh dup if        (* get vehicle env room *)
        ourRoom !
        ourRoom @ DoRecContainedRooms          (* rec contained rooms *)
        ourRoom @ recycle                             (* rec env room *)
        ourVehicle @ "@v/key" getprop ourString !
        ourVehicle @ recycle                    (* rec vehicle object *)
        ">>  Vehicle recycled." Tell
        background
        ourString @ if
          ourString @ string? not if
            ourString @ intostr ourString !
          then
        else
          exit
        then
        #0                             (* scan db; find keys; recycle *)
        begin
          dup dbtop dbcmp not while
          dup ok? if
            dup "@v/key" getprop dup if
              dup string? not if intostr then
              ourString @ smatch if
                dup "@v/env" getpropstr not if
                  dup 1 + swap recycle
                then
              then
            else
              pop
            then
          then
          1 +
        repeat
        pop
      else
        ">>  $name is not a vsys vehicle." 
        ourVehicle @ name "$name" subst Tell
      then
    else
      ">>  Permission denied." Tell
    then
  else
    ">>  Usage: $com <vehicle obj>"
    command @ "$com" subst Tell
  then
;
  
: main
  
  "me" match me !
  DoInit
  
  dup if
    ourString !
  then
  
  ourString @ if
    "#help"    ourString @ stringpfx if DoHelp    exit then
    "#install" ourString @ stringpfx if DoInstall exit then
    DoVrecycle
  else
    ">>  Usage: $com <vehicle object>"
    command @ "$com" subst Tell
  then
;
.
c
q
@set vsys-@vrecycle=W