ArtMOO
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
G:/dev/qt/MOO/ServerCore/object.h
Go to the documentation of this file.
00001 #ifndef OBJECT_H
00002 #define OBJECT_H
00003 
00004 #include "mooglobal.h"
00005 
00006 #include <QString>
00007 #include <QList>
00008 #include <QVariant>
00009 #include <QMap>
00010 #include <QMultiMap>
00011 #include <QDataStream>
00012 #include <QVariant>
00013 #include "verb.h"
00014 #include "property.h"
00015 #include "task.h"
00016 
00017 class ObjectManager;
00018 
00019 #ifdef USING_PHYSICS
00020 class btCollisionShape;
00021 class btRigidBody;
00022 #endif
00023 
00024 class Object
00025 {
00026 private:
00027         Object( void );
00028 
00029         virtual ~Object( void );
00030 
00031         friend class ObjectManager;
00032         friend class lua_object;
00033 
00034 public:
00035 
00036 private:
00037         ObjectId                        mId;
00038 
00039         // Fundamental Object Attributes
00040 
00041         bool                            mPlayer;                // whether or not the object represents a player
00042         ObjectId                        mParent;                // The object that is its parent
00043         QList<ObjectId>         mChildren;              // A list of the objects that are its children
00044 
00045 #ifdef USING_PHYSICS
00046         btCollisionShape        *mCollisionShape;
00047         btRigidBody                     *mRigidBody;
00048 #endif
00049 
00050         // Built-in Properties
00051 
00052         QString                         mName;                  // the usual name for this object
00053         ObjectId                        mOwner;                 // the player who controls access to it
00054         ObjectId                        mLocation;              // where the object is in virtual reality
00055         QList<ObjectId>         mContents;              // a list of objects, the inverse of `location'
00056         bool                            mProgrammer;    // does the object have programmer rights?
00057         bool                            mWizard;                // does the object have wizard rights?
00058         bool                            mRead;                  // is the object publicly readable?
00059         bool                            mWrite;                 // is the object publicly writable?
00060         bool                            mFertile;               // is the object fertile?
00061         bool                            mRecycled;              //
00062 
00063         // Properties and Verbs
00064 
00065         QMap<QString,Verb>                      mVerbs;
00066         QMap<QString,Property>          mProperties;    // Properties defined on this object
00067         QList<Task>                                     mTasks;
00068 
00069         bool propFindRecurse( const QString &pName, Property **pProp, Object **pObject );
00070         void propDeleteRecurse( const QString &pName );
00071 
00072         bool verbFindRecurse( const QString &pName, Verb **pVerb, Object **pObject, ObjectId pDirectObjectId, const QString &pPreposition, ObjectId pIndirectObjectId );
00073 
00074         inline QMap<QString,Verb> &verbmap( void )
00075         {
00076                 return( mVerbs );
00077         }
00078 
00079         inline QMap<QString,Property> &propmap( void )
00080         {
00081                 return( mProperties );
00082         }
00083 
00084 public:
00085         void move( Object *pWhere );
00086         void setParent( ObjectId pNewParentId );
00087 
00088         void save( QDataStream &pData ) const;
00089         void load( QDataStream &pData );
00090 
00091         bool matchName( const QString &pName );
00092 
00093         typedef enum Permissions
00094         {
00095                 READ    = ( 1 << 0 ),
00096                 WRITE   = ( 1 << 1 ),
00097                 FERTILE = ( 1 << 2 )
00098         } Permissions;
00099 
00100         quint16 permissions( void ) const;
00101         void setPermissions( quint16 pPerms );
00102 
00103         //
00104 
00105         void ancestors( QList<ObjectId> &pList );
00106         void descendants( QList<ObjectId> &pList );
00107 
00108         // Define property on this object
00109         void propAdd( const QString &pName, Property &pProp );
00110         void propDelete( const QString &pName );
00111         void propClear( const QString &pName );
00112         void propSet( const QString &pName, const QVariant &pValue );
00113         bool propFind( const QString &pName, Property **pProp, Object **pObject );
00114         void propNames( QStringList &pList );
00115 
00116         Property *prop( const QString &pName );
00117         Property *propParent( const QString &pName );
00118 
00119         inline const QMap<QString,Property> &properties( void ) const
00120         {
00121                 return( mProperties );
00122         }
00123 
00124         void verbAdd( const QString &pName, Verb &pVerb );
00125         void verbDelete( const QString &pName );
00126         bool verbFind( const QString &pName, Verb **pVerb, Object **pObject, ObjectId pDirectObjectId = OBJECT_NONE, const QString &pPreposition = "", ObjectId pIndirectObjectId = OBJECT_NONE );
00127 
00128         Verb *verbMatch( const QString &pName, ObjectId pDirectObjectId = OBJECT_NONE, const QString &pPreposition = "", ObjectId pIndirectObjectId = OBJECT_NONE );
00129         Verb *verbParent( const QString &pName, ObjectId pDirectObjectId = OBJECT_NONE, const QString &pPreposition = "", ObjectId pIndirectObjectId = OBJECT_NONE );
00130 
00131         inline const QMap<QString,Verb> &verbs( void ) const
00132         {
00133                 return( mVerbs );
00134         }
00135 
00136         Verb *verb( const QString &pName );
00137 
00138         //
00139 
00140         inline operator ObjectId ( void ) const
00141         {
00142                 return( mId );
00143         }
00144 
00145         inline ObjectId id( void ) const
00146         {
00147                 return( mId );
00148         }
00149 
00150         inline const QString &name( void ) const
00151         {
00152                 return( mName );
00153         }
00154 
00155         inline bool player( void ) const
00156         {
00157                 return( mPlayer );
00158         }
00159 
00160         inline ObjectId location( void ) const
00161         {
00162                 return( mLocation );
00163         }
00164 
00165         inline ObjectId parent( void ) const
00166         {
00167                 return( mParent );
00168         }
00169 
00170         inline const QList<ObjectId> &children( void ) const
00171         {
00172                 return( mChildren );
00173         }
00174 
00175         inline const QList<ObjectId> &contents( void ) const
00176         {
00177                 return( mContents );
00178         }
00179 
00180         inline bool valid( void ) const
00181         {
00182                 return( !mRecycled );
00183         }
00184 
00185         inline bool programmer( void ) const
00186         {
00187                 return( mProgrammer );
00188         }
00189 
00190         inline bool wizard( void ) const
00191         {
00192                 return( mWizard );
00193         }
00194 
00195         inline bool fertile( void ) const
00196         {
00197                 return( mFertile );
00198         }
00199 
00200         inline ObjectId owner( void ) const
00201         {
00202                 return( mOwner );
00203         }
00204 
00205         inline bool recycle( void ) const
00206         {
00207                 return( mRecycled );
00208         }
00209 
00210         inline bool read( void ) const
00211         {
00212                 return( mRead );
00213         }
00214 
00215         inline bool write( void ) const
00216         {
00217                 return( mWrite );
00218         }
00219 
00220         inline void setOwner( ObjectId pOwner )
00221         {
00222                 mOwner = pOwner;
00223         }
00224 
00225         void setPlayer( bool pPlayer )
00226         {
00227                 mPlayer = pPlayer;
00228         }
00229 
00230         inline void setName( const QString &pName )
00231         {
00232                 mName = pName;
00233         }
00234 
00235         inline void setProgrammer( bool pProgrammer )
00236         {
00237                 mProgrammer = pProgrammer;
00238         }
00239 
00240         inline void setWizard( bool pWizard )
00241         {
00242                 mWizard = pWizard;
00243         }
00244 
00245         inline void setRead( bool pRead )
00246         {
00247                 mRead = pRead;
00248         }
00249 
00250         inline void setWrite( bool pWrite )
00251         {
00252                 mWrite = pWrite;
00253         }
00254 
00255         inline void setFertile( bool pFertile )
00256         {
00257                 mFertile = pFertile;
00258         }
00259 
00260         inline void setRecycle( bool pRecycle )
00261         {
00262                 mRecycled = pRecycle;
00263         }
00264 };
00265 
00266 #endif // OBJECT_H