Table of Contents

Class: Container mudlib/core.py

Container base class. Containers can hold other objects.

Containers have a maximum capacity that determines how much can be carried. When an object is entered into the container's inventory, its volume is added to the existing volume of the container (and its inventory). If that total volume exceeds the capacity of the container, then the object cannot be added.

Containers can be rigid or not. Rigid containers always take up as much space in their environment container (if there is one), no matter how much they're carrying. Non-rigid containers only take up as much space as needed by the items contained in them.

Base Classes   
Object
    MudObject
Methods   
addObject
canAddObject
contains
createContainer
createObject
destroyContainer
destroyObject
enterContainer
getCapacity
getDeepInventory
getInventory
getIsRigid
getLongDescription
getMaximumWeight
getVolume
leaveContainer
refreshContainer
refreshObject
removeObject
setCapacity
setIsRigid
setMaximumWeight
  addObject 
addObject ( self,  newObject )

Add the given object to this container.

If the object cannot be added to this container then this method returns 0. Otherwise it returns 1.

Note that you should NOT generally override this method. If you're interested in being informed of when new objects enter the inventory of this container, override the enterContainer method.

arguments:

newObject
(object) an object to be added to this container

returns:

(int) 1 if it was successfully added, 0 if not

  canAddObject 
canAddObject ( self,  potentialObject )

Determine if this container can hold the given object.

  1. It can't be this object

  2. It can't contain this object.

  3. It can't already be contained by this object.

  4. It's volume can't overflow our capacity.

  5. The canEnterInventory method must return true.

arguments:

potentialObject
(object) the object we're testing for addability
returns:

(int) 1 if it can be added, 0 if not

  contains 
contains ( self,  targetObject )

Determine if this container contains the given object.

Returns 1 if this container contains the object anywhere within its deep inventory, 0 otherwise.

arguments:

targetObject
(object) the object we want

returns:

(int) 1 if it is contained, 0 if not

  createContainer 
createContainer ( self )

The "constructor" for containers.

This method should be overriden, if necessary, and any initialization put in the overriden version. Note that you should NOT override the __init__ or createObject methods.

  createObject 
createObject ( self )

Overrides Object.createObject. Do NOT override!

If you want to do some initialization, you should override the createContainer method.

  destroyContainer 
destroyContainer ( self )

Invoked when this container is destroyed.

This method will be invoked by the destroyObject method after it has finished with any container-specific cleanup. If you want to do your own cleanup, then you should override this method.

  destroyObject 
destroyObject ( self )

Overrides Object.destroyObject. Do NOT override!.

This method performs any necessary cleanup specific to containers. If you want to do any cleanup of your own, you should override the destroyContainer method, which is invoked by this method after all other cleanup is done.

  enterContainer 
enterContainer ( self,  newObject )

Invoked after an object is added to this container's inventory.

This method is invoked by the addObject method once an object is successfully added to this container. If you want to do any special processing when an object is added, you should override this method. You should NOT generally override the addObject method.

arguments:

newObject
(object) the object entering this container
  getCapacity 
getCapacity ( self )

Retrieve this container's maximum capacity.

The maximum capacity of a container is used when determining whether the container can hold an additional object. The total volume of the objects in the container's inventory cannot exceed the container's maximum capacity. You can override this method if you want capacity to be determined on the fly.

returns:

(int) the maximum capacity of the container

FIXME - what units is this measured in?

  getDeepInventory 
getDeepInventory ( self )

Retrieve the deep (nested) inventory of this container.

The deep inventory includes not only the inventory of this container, but also the inventory of any containers in this container, and the inventory of any containers inside those containers, and so on.

returns:

(list of objects) the recursive inventory of this container

  getInventory 
getInventory ( self )

Retrieve the direct (not nested) inventory of this container.

returns:

(list of objects) all the objects in this container's inventory

  getIsRigid 
getIsRigid ( self )

Determine whether this container is rigid.

If the container is rigid (such as a box), then it will always have the same volume. If it is not rigid (such as a canvas bag), then its volume will be qual to the total volume of all the objects in its inventory. This method returns 1 if this container is rigid, 0 otherwise.

returns:

(int) 1 if rigid, 0 if not

  getLongDescription 
getLongDescription ( self )

Overrides Object.getLongDescription

This version appends a description of this container's inventory to the long description.

returns:

(string) the long description plus the inventory of this container

  getMaximumWeight 
getMaximumWeight ( self )

Retriever this container's maximum weight.

The maximum weight that this container can carry is used when determining whether the container can hold an additional object. The total weight of the objects in the container cannot exceed the container's maximum weight. You can override this method if you want maximumWeight to be determined on the fly.

returns:

(int) the maximum weight of the container

  getVolume 
getVolume ( self )

Overrides Object.getVolume.

If this container is rigid, then this method returns the volume of the container. Otherwise, it returns the total volume of the object in this container's inventory.

returns:

(int) the current volume of the container--this is how much free space there is

FIXME - what units is this measured in?

  leaveContainer 
leaveContainer ( self,  oldObject )

Invoked after an object is removed from this container's inventory.

This method is invoked by the removeObject method once an object is successfully removed from this container. If you want to do any special processing when an object is removed, you should override this method. You should NOT generally override the removeObject method.

arguments:

oldObject
(object) the object leaving this container
  refreshContainer 
refreshContainer ( self )

Invoked during container refreshment.

This method is invoked by the refreshObject method after any container-specific refreshment has occured. If you need to perform any refreshment, you should override this method.

  refreshObject 
refreshObject ( self )

Overrides Object.refreshObject. Do NOT override!

This version takes care of any necessary refreshment specific to containers and then invokes the refreshContainer method. If you need to perform any refreshment yourself, you should override the refreshContainer method.

  removeObject 
removeObject ( self,  oldObject )

Remove the given object from this container.

Note that you should NOT generally override this method. If you're interested in being informed when objects leave this container's inventory, override the leaveContainer method.

arguments:

oldObject
(object) the object to remove from this container

returns:

(int) 1 if successful, 0 if not

  setCapacity 
setCapacity ( self,  capacity )

Sets the maximum capacity of this container.

The maximum capacity of the container is used when determining whether the container can hold an additional object. The total volume of the objects in this container's inventory cannot exceed this container's maximum capacity.

arguments:

capacity
(int) the capacity to set to this container

FIXME - what units is this measured in?

  setIsRigid 
setIsRigid ( self,  isRigid )

Set whether this container is rigid.

If the container is rigid (such as a box), then it will always have the same volume. If it is not rigid (such as a canvas bag), then its volume will be equal to the total volume of all the objects in its inventory.

arguments:

isRigid
(int) 1 if it's rigid, and 0 if not
  setMaximumWeight 
setMaximumWeight ( self,  maxWeight )

Sets the maximum weight that this container can carry.

The maximum weight that this container can carry is used when determining whether the container can hold an additional object. The total weight of the objects in the container cannot exceed the container's maximum weight.

arguments:

maxWeight
(int) the maximum weight this container can carry

Table of Contents

This document was automatically generated on Thu Jan 24 08:57:43 2002 by HappyDoc version 2.0