Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

SCA_AddObjectActuator.cpp

Go to the documentation of this file.
00001 //
00002 // Add an object when this actuator is triggered
00003 //
00004 // Version: $Id: SCA_AddObjectActuator_cpp-source.html,v 1.1 2001/02/01 12:25:11 coockie Exp $
00005 
00006 #include "SCA_IActuator.h"
00007 #include "SCA_AddObjectActuator.h"
00008 #include "SCA_IScene.h"
00009 #include <iostream>
00010 //  #include "ConstExpr.h"
00011 
00012 //  blender func: void add_dupli_life(Object *o1, Object *o2, int t);
00013 /* ------------------------------------------------------------------------- */
00014 /* Python functions                                                          */
00015 /* ------------------------------------------------------------------------- */
00016 
00017 /* Integration hooks ------------------------------------------------------- */
00018 PyTypeObject SCA_AddObjectActuator::Type = {
00019         PyObject_HEAD_INIT(&PyType_Type)
00020         0,
00021         "SCA_AddObjectActuator",
00022         sizeof(SCA_AddObjectActuator),
00023         0,
00024         PyDestructor,
00025         0,
00026         __getattr,
00027         __setattr,
00028         0, //&MyPyCompare,
00029         __repr,
00030         0, //&cvalue_as_number,
00031         0,
00032         0,
00033         0,
00034         0
00035 };
00036 
00037 PyParentObject SCA_AddObjectActuator::Parents[] = {
00038         &SCA_IActuator::Type,
00039         &SCA_ILogicBrick::Type,
00040         &CValue::Type,
00041         NULL
00042 };
00043 PyMethodDef SCA_AddObjectActuator::Methods[] = {
00044   {"setObject", (PyCFunction) SCA_AddObjectActuator::sPySetObject, METH_VARARGS, SetObject_doc},
00045   {"setTime", (PyCFunction) SCA_AddObjectActuator::sPySetTime, METH_VARARGS, SetTime_doc},
00046   {"getObject", (PyCFunction) SCA_AddObjectActuator::sPyGetObject, METH_VARARGS, GetObject_doc},
00047   {"getTime", (PyCFunction) SCA_AddObjectActuator::sPyGetTime, METH_VARARGS, GetTime_doc},
00048   {NULL,NULL} //Sentinel
00049 };
00050 
00051 
00052 PyObject*
00053 SCA_AddObjectActuator::_getattr(char* attr)

00054 {
00055   _getattr_up(SCA_IActuator);
00056 }
00057 
00058 /* 1. setObject */
00059 char SCA_AddObjectActuator::SetObject_doc[] = 
00060 "setObject(name)\n"
00061 "\t- name: string\n"
00062 "\tSets the object that will be added. There has to be an object\n"
00063 "\tof this name. If not, this function does nothing.\n";
00064 PyObject* SCA_AddObjectActuator::PySetObject(PyObject* self, 
00065                                                                                    PyObject* args, 
00066                                                                                    PyObject* kwds) {    
00067         char* objectname;
00068         
00069         if (!PyArg_ParseTuple(args, "s", &objectname)) {
00070                 return NULL;            
00071         }
00072         CValue* gameobj = SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(CCString(objectname));
00073         
00074         m_OriginalObject= (CValue*)gameobj;
00075         
00076         Py_Return;      
00077 }
00078 
00079 /* 2. setTime */
00080 char SCA_AddObjectActuator::SetTime_doc[] = 
00081 "setTime(duration)\n"
00082 "\t- duration: integer\n"
00083 "\tSets the lifetime of the object that will be added, in frames. \n"
00084 "\tIf the duration is negative, it is set to 0.\n";
00085 PyObject* SCA_AddObjectActuator::PySetTime(PyObject* self, 
00086                                                                                   PyObject* args, 
00087                                                                                   PyObject* kwds) {
00088         int deltatime;
00089         
00090         if (!PyArg_ParseTuple(args, "i", &deltatime)) {
00091                 return NULL;
00092         }
00093         
00094         m_timeProp= deltatime;
00095         if (m_timeProp < 0) m_timeProp = 0;
00096         
00097         Py_Return;
00098 }
00099 
00100 /* 3. getTime */
00101 char SCA_AddObjectActuator::GetTime_doc[] = 
00102 "GetTime()\n"
00103 "\tReturns the lifetime of the object that will be added.\n";
00104 PyObject* SCA_AddObjectActuator::PyGetTime(PyObject* self, 
00105                                                                                   PyObject* args, 
00106                                                                                   PyObject* kwds) {
00107         return PyInt_FromLong(m_timeProp);
00108 }
00109 /* 4. getObject */
00110 char SCA_AddObjectActuator::GetObject_doc[] = 
00111 "getObject()\n"
00112 "\tReturns the name of the object that will be added.\n";
00113 PyObject* SCA_AddObjectActuator::PyGetObject(PyObject* self, 
00114                                                                                         PyObject* args, 
00115                                                                                         PyObject* kwds) {
00116         return PyString_FromString(m_OriginalObject->GetName());
00117 }
00118 
00119 /* 5. getLinearVelocity                                                 */
00120 char SCA_AddObjectActuator::GetLinearVelocity_doc[] = 
00121 "GetLinearVelocity()\n"
00122 "\tReturns the linear velocity that will be assigned to \n"
00123 "\tthe created object.\n";
00124 PyObject* SCA_AddObjectActuator::PyGetLinearVelocity(PyObject* self, 
00125                                                                                                  PyObject* args, 
00126                                                                                                  PyObject* kwds) {
00127         PyObject *retVal = PyList_New(3);
00128 
00129         PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_linear_velocity[0]));
00130         PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_linear_velocity[1]));
00131         PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_linear_velocity[2]));
00132         
00133         return retVal;
00134 }
00135 
00136 /* 6. setLinearVelocity                                                 */
00137 char SCA_AddObjectActuator::SetLinearVelocity_doc[] = 
00138 "setLinearVelocity(vx, vy, vz)\n"
00139 "\t- vx: float\n"
00140 "\t- vy: float\n"
00141 "\t- vz: float\n"
00142 "\tAssign this velocity to the created object. \n";
00143 PyObject* SCA_AddObjectActuator::PySetLinearVelocity(PyObject* self, 
00144                                                                                                  PyObject* args, 
00145                                                                                                  PyObject* kwds) {
00146         float vecArg[3];
00147         if (!PyArg_ParseTuple(args, "fff", &vecArg[0], &vecArg[1], 
00148                                                   &vecArg[2])) {
00149                 return NULL;
00150         }
00151         m_linear_velocity.setValue(vecArg);
00152         Py_Return;
00153 }
00154 
00155 
00156 /* ------------------------------------------------------------------------- */
00157 /* Native functions                                                          */
00158 /* ------------------------------------------------------------------------- */
00159 
00160 SCA_AddObjectActuator::SCA_AddObjectActuator(SCA_IObject *gameobj, 
00161                                                                                    CValue* original,
00162                                                                                    int time, 
00163                                                                                    SCA_IScene* scene,
00164                                                                                    const MT_Vector3& linvel,
00165                                                                                    bool local,
00166                                                                                    PyTypeObject* T)
00167         : SCA_IActuator(gameobj, T),
00168           m_OriginalObject(original),
00169           m_scene(scene),
00170           m_linear_velocity(linvel),
00171           m_localFlag(local)

00172 {
00173         // Some init stuff? not here, just call my super();
00174         // further, just some safe presets
00175         m_timeProp = time;
00176 } /* End of constructor */
00177 
00178 SCA_AddObjectActuator::~SCA_AddObjectActuator()

00179 { 
00180         // there's nothing to be done here, really....
00181 } 
00182 
00183 /* end of destructor */
00184 
00185 bool SCA_AddObjectActuator::Update(double curtime,double deltatime)

00186 {
00187         bool result = false;    
00188         bool bNegativeEvent = IsNegativeEvent();
00189         
00190         if (bNegativeEvent)
00191                 return false; // do nothing on negative events
00192         
00193         // add an identical object, with properties inherited from the parent object
00194 
00195         //SCA_IObject* replica = (SCA_IObject*) (m_OriginalObject ? m_OriginalObject->GetReplica() : NULL);
00196         
00197         // now it needs to be added to the current scene !
00198         if (m_OriginalObject)
00199         {
00200                 SCA_IObject* replica = m_scene->AddReplicaObject(m_OriginalObject,GetParent(),m_timeProp );
00201                 replica->setLinearVelocity(m_linear_velocity,m_localFlag);
00202         }
00203         
00204         return false;
00205 }

Generated at Thu Feb 1 13:03:09 2001 for Ketsji Game Engine by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000