[DGD] Auto and Driver objects

Ben Chambers bjchamb at bellsouth.net
Sun May 25 03:40:54 CEST 2003


If I have a base object, such as GameObject, with the following functions:

/* move the object into this object if it is a container */
int moveInto(object newItem)
{
   return -1;
}

/* move the object out of this object if it is a container */
int moveFrom(object oldItem)
{
   return -1;
}

/* move me between start and end */
int move(object start, object end)
{
   if (container != start) /* if I'm not at the start */
      return -1;
   start->moveFrom(this);
   end->moveInto(this);
   return 1;
}

I know the names of some things are wrong, especially the whole 'this'
thing, but I'm too lazy to look up the real name right now.  Obviously the
move would be atomic, so that if the start or end failed, it wouldn't work.

Then I wanted to make an object for a container like this:


inherit base;
/* this function is defined in the end object, if necessary to do special
checking or messages  */
int objectAdded(object item)
{
   return 1;
}

/* this function is defined in the end object, if necessary to do special
checking or messages */
int objectRemoved(object item)
{
   return 1;
}

/* move the object into this object if it is a container */
int moveInto(object newItem)
{
   items[newItem->id()] = items[newItem->id()] + 1; /* increment the count
of how many there are */
   return objectAdded(newItem); /* this is some function defined by the end
user */
}

/* move the object out of this object if it is a container */
int moveFrom(object oldItem)
{
   if (items[oldItem->id()] == 0)
      return -1; /* nothing to remove */
   items[oldItem->id()] = items[oldItem->id()] - 1; /* increment the count
of how many there are */
   return objectRemoved(oldItem); /* this is some function defined by the
end user */
}

Then to make a specific backpack or something I would want to inherit both
the base object and the container object, but with the container object's
versions of move from and move into overriding the versions defined in the
base object.  Would this be possible?  Basically, the base version provides
the default 'You can't move that from that to that' behavior, while the
container provides the you can move it, and the end object is the specific
version of how this is done.

_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list