4
name
"generic container"
/
contents
'()
/
init
(method ()
    (begin (set contents '())
           (pass)))
/
destroy
(method ()
	(begin (foreach (i contents) (i:go-home))
	       (pass)))
/
accept-move
;; whenever an object tries to move into this, it asks this if it's ok by
;; using the 'accept-move' method
;; for now, this is a move-free-for-all ...
;; make sure that an object will always accept something it owns.
(method ()
	(begin (set contents ($utils:set-add caller contents))
	       1))
/
std-match
(method (mname)
  (set mname ($utils:strip-spaces mname)
    (or (foreach (c contents)
          (if (c:name-match mname) (return c)))
        (pass mname))))
/
accept-exit
(method (exit) 1)
/
remove
(method (obj)
	(if (or (write-ok? caller) (= obj caller))
      	  (set contents ($utils:set-remove obj contents))
	  (raise E_PERM
            (+ "cannot remove " (tostr obj) " from " (tostr this)))))
/
get-contents
(method () contents)
/
non-exit-contents
;; have to give it contents as a parameter
(method (c)
	(if c (if (call (car c) descends-from? $exit)
	          (non-exit-contents (cdr c))
	          (cons (car c) (non-exit-contents (cdr c))))
	      '()))
/
list-exits
;; have to give it the contents as a parameter
(method (c)
	(if c (if (call (car c ) descends-from? $exit)
		  (cons (car c) (list-exits (cdr c)))
		  (list-exits (cdr c)))
	    '()))
/
get-exits-string
(method ()
   (var ex (var es
     (if (set ex (list-exits contents))
       (set es "Exits: "
	 (foreach (e ex)
	   (set es (+ es " " (e:get-name) " ")))
         es)
       "No obvious exits\n"))))
/
get-visible-contents
(method () (non-exit-contents (get-contents)))
/
get-contents-string
(method () 
	(var c (begin (set c (get-visible-contents))
	     (if c
	      (if (> (length c) 1)
	         (+ (get-rest-contents (cdr c))
	            "and " (call (car c) get-name))
	         (call (car c) get-name))
	      ""))))
/
get-rest-contents
(method (clist)
	(if clist
	   (+ (get-rest-contents (cdr clist))
	      (call (car clist) get-name) ", ")
	   ""))		
/
match-exit-content
(method (instring)
	(foreach (c contents)
	   (if (and (c:descends-from? $exit)
                    (c:name-match instring))
			(return c))))
/
match-non-exit
(method (instring)
	(foreach (c contents)
	   (if (and (not (c:descends-from? $exit))
		    (c:name-match instring))
	     (return c))))
/
get-internal-description
(method () (get-description))
/
match-content
(method (instring)
	(foreach (c contents)
	   (if (c:name-match instring) (return c))))
/
announce
(method (instring)
	(ignore E_VAR_NOT_FOUND
	  (begin
	    (foreach (c contents)
	      (c:tell instring))
	    instring)))
/
announce-but
(method (instring except)
	(ignore E_VAR_NOT_FOUND
	  (foreach (c contents)
	    (if (not (= c except))
               (c:tell instring)))))
/
try-command-in
;; this is called when an object is trying to find a command inside of a room.
;; it searches the command list on this, then asks the contents to respond,
;; and finally it checks for exits with the right name.
(method (instring)
	(or (foreach (c (matchcmd instring))
	      (if ((car c) (index 2 c)) (return 1)))
	    (foreach (c contents)
	      (if (and (not (= c caller)) (c:try-command instring))
	         (return 1)))
	    (var exit
	      (if (set exit (match-exit-content instring))
                  (call exit activate caller)
                  0))))
/
look-at
(method ()
  (begin
    (player:tell-line name)
    (player:tell-line (get-internal-description))
    (if (player:tell (get-contents-string))
      (player:tell "\n")
      "No contents to tell")))
/
/
/+++++++++ end of object #5 ... no lines after this ++++++++++