[DGD] How would this code work?
    Ben Chambers 
    bjchamb at bellsouth.net
       
    Sun May 25 21:11:11 CEST 2003
    
    
  
------------------------------------------------------------
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
    
    
More information about the DGD
mailing list