[DGD] How would this code work?
Ben Chambers
bjchamb at bellsouth.net
Sun May 25 21:36:11 CEST 2003
Cool, thanks! How exactly does the performance of everything respond to
massive multiple inheritance? Such as a backpack that is not only a
container but also inherits aspects of a weapon or something like that? I
assume it still works in a satisfactory manner?
----- Original Message -----
From: "Noah Gibbs" <noah_gibbs at yahoo.com>
To: <dgd at list.imaginary.com>
Sent: Sunday, May 25, 2003 3:26 PM
Subject: Re: [DGD] How would this code work?
> Here's something really simple: it's not
> "container->moveInto()", it's "container::moveInto()"
> when container is something you inherit from.
>
> Also, in container it doesn't look like you're
> initializing mhContents, so you'll probably get an
> error the first time you add an object into the
> mapping, something about an invalid argument for the
> left side of "+", because you're trying to add nil to
> 1, and you can't do that.
> That's assuming you're in full-on error checking
> mode, of course. In modes where nil is equivalent to
> 0 there'll be no problem at all.
>
> But in any case, yes, your idea looks sound.
> Phantasmal, not shockingly, does a lot of these same
> things :-)
>
> --- Ben Chambers <bjchamb at bellsouth.net> wrote:
> >
> ------------------------------------------------------------
> > GameObject.c (this is one of the base objects that
> > will be provided)
> >
> ------------------------------------------------------------
> > /* move the object <a> into this object
> > * throws an error if this is not possible
> > */
> > atomic void moveInto(object a)
> > {
> > error("This object is not a container.");
> > }
> >
> > /* move the object <a> out of this object
> > * throws an error if this is not possible
> > */
> > atomic void moveFrom(object a)
> > {
> > error("This object is not a container.");
> > }
> >
> > /* move this object from object <a> into object <b>
> > * throws an error if this is not possible
> > */
> > atomic void move(object a, object b)
> > {
> > a->moveFrom(this_object());
> > b->moveInto(this_object());
> > }
> >
> ------------------------------------------------------------
> > Container.c (this is one of the base objects that
> > will be provided)
> >
> ------------------------------------------------------------
> > inherit "GameObject.c";
> > mapping mhContents;
> > /* move the object <a> into this object
> > * throws an error if this is not possible
> > */
> > atomic void moveInto(object a)
> > {
> > mhContents[object_name(a)] =
> > mhContents[object_name(a)] + 1;
> > }
> >
> > /* move the object <a> out of this object
> > * throws an error if this is not possible
> > */
> > atomic void moveFrom(object a)
> > {
> > if (!mhContents[object_name(a)])
> > error("Cannot remove something that isn't
> > here.");
> > mhContents[object_name(a)] =
> > mhContents[object_name(a)] - 1;
> > }
> >
> ------------------------------------------------------------
> > Backpack.c (this is something a wizard might make)
> >
> ------------------------------------------------------------
> > inherit "GameObject.c";
> > inherit container "Container.c";
> >
> > int miCapacity;
> > int miContentSize;
> >
> > int remaining_capacity()
> > {
> > return miCapacity - miContentSize;
> > }
> >
> > /* move the object <a> into this object
> > * throws an error if this is not possible
> > */
> > atomic void moveInto(object a)
> > {
> > container->moveInto(a);
> >
> > if (a->item_size() > remaining_capacity())
> > error("That will not fit.");
> > miContentSize += a->item_size();
> > }
> >
> > /* move the object <a> out of this object
> > * throws an error if this is not possible
> > */
> > atomic void moveFrom(object a)
> > {
> > container->moveFrom(a);
> >
> > miContentSize -= a->item_size();
> >
> > }
> >
> >
> >
> >
> > Would it behave as expected? Are there any problems
> > that code like this
> > could cause in the future? Any suggestions for ways
> > of improving this?
> >
> >
> _________________________________________________________________
> > List config page:
> http://list.imaginary.com/mailman/listinfo/dgd
>
>
> =====
> ------
> noah_gibbs at yahoo.com
>
> __________________________________
> Do you Yahoo!?
> The New Yahoo! Search - Faster. Easier. Bingo.
> http://search.yahoo.com
> _________________________________________________________________
> List config page: http://list.imaginary.com/mailman/listinfo/dgd
>
_________________________________________________________________
List config page: http://list.imaginary.com/mailman/listinfo/dgd
More information about the DGD
mailing list