Newsgroups: rec.arts.int-fiction
Path: gmd.de!jvnc.net!yale.edu!qt.cs.utexas.edu!cs.utexas.edu!uunet!scorn!jondr
From: jondr@sco.COM (Desi The Three-Armed Wonder Comic)
Subject: Re: OK, OK, OK, this is Alan...
Reply-To: jondr@sco.com
Organization: The Santa Cruz Operation, Inc.
Date: Mon, 02 Nov 1992 22:06:58 GMT
Message-ID: <1992Nov02.220658.3788@sco.com>
References: <1992Oct28.191757.11672@ida.liu.se>
Sender: news@sco.com (News admin)
Lines: 87


I am not thoni@ida.liu.se (Thomas Nilsson).  I didn't say:
>Also a while back someone (other) said he finally had finished his
>code to handle containers in TADS (I think). Probably that handling
>was very elaborate and does not at all compare to what you get with
>the following Alan definitions:

That was me.  I wrote it in ADVSYS, actually.  And once the basic framework
was in place, doing stuff like what you have below wasn't very complicated.

>	Object chest At tresury
>	    Container
>	        Limits
>		    size 5 Else "It doesn't fit in the chest."
>		    Count 6 Else "There is only room for 6 items."
>	End Object chest.

I didn't implement size vs room, so it's not an issue although it would only
be a few more lines of code to do it.  An object like that would look like
this in advsys:

	(container chest
	  (noun chest)
	  (adjective wooden heavy)
	  (property
	   initial-location treasury
	   capacity 5
	   description "There is a heavy wooden chest on the ground."
	   short-description "chest"))

If I wanted to have it specially handle requests, I could attach methods to
the end.  For instance, say I wanted to have a special case if the user
tried to attack it...

         (method (m-attack)
		 (die "You attack the chest which, unfortunately for you,
happened to be made of Sapient Pearwood.  As your fist strikes the wood, a
giant gaping mouth opens and the chest sucks you into a dimension which is
strangely devoid of oxygen..."))

This little bit of code goes with the chest object, making the code very
object-oriented and simple to debug.

>	Syntax
>	    put_in = 'put' (obj) 'in' (cont)
>		Where cont Isa Container
>		    Else "You can not put anything inside the $2."
>	Verb put_in
>	    Check obj In inventory
>		Else "You don't have the" Say obj.
>	    Does
>		Locate obj In cont.
>	End Verb put_in.

Here's my "put something in something" code.  It requires a few supporting
subroutines that i'm not going to include in this post (in-pocket,
in-location, container?, surface?, open?, find-load and putin).  Anyway, I
hope this gives a flavor of what advsys is like.  This routine doesn't use
the method facility, because I haven't needed to special case any "put"
actions.  Note: you really have to be a LISP fan to like advsys code.
Fortunately, I overcame initial LISP-phobia and now I think it's dead sexy.

(action put
  (verb put insert)
  (direct-object)
  (preposition in on)
  (indirect-object)
  (code
    (setq %dobject (in-pocket $dobject))
    (setq %iobject (in-location $iobject))
    (if (or (container? %iobject)
            (surface? %iobject))
	(if (open? %iobject)
	    (if
		(> (+ (find-load %iobject) (getp %dobject size))
		   (getp %iobject capacity))
		(print "It won't fit.")
	      (progn
		(putin %dobject %iobject)
		(print "Done.")))
	  (inform "The " $iobject " is closed."))
	  (print "You can't put anything in or on that!"))))

-- 
Jon Drukman (God's personal DJ)                 uunet!sco!jondr   jondr@sco.com
-------------------------------------------------------------------------------
Why kill time when you can kill yourself?
