2002-10-12 11:37:38 +00:00
//
// Add an object when this actuator is triggered
//
// $Id$
//
2008-04-16 22:40:48 +00:00
// ***** BEGIN GPL LICENSE BLOCK *****
2002-10-12 11:37:38 +00:00
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
2008-04-16 22:40:48 +00:00
// of the License, or (at your option) any later version.
2002-10-12 11:37:38 +00:00
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
// All rights reserved.
//
// The Original Code is: all of this file.
//
// Contributor(s): none yet.
//
2008-04-16 22:40:48 +00:00
// ***** END GPL LICENSE BLOCK *****
2002-10-12 11:37:38 +00:00
// Previously existed as:
// \source\gameengine\GameLogic\SCA_AddObjectActuator.cpp
// Please look here for revision history.
# include "KX_SCA_AddObjectActuator.h"
# include "SCA_IScene.h"
# include "KX_GameObject.h"
# include "KX_IPhysicsController.h"
2008-09-06 14:13:31 +00:00
# include "PyObjectPlus.h"
2008-09-06 02:46:11 +00:00
2002-11-25 15:29:57 +00:00
# ifdef HAVE_CONFIG_H
# include <config.h>
# endif
2002-10-12 11:37:38 +00:00
/* ------------------------------------------------------------------------- */
/* Native functions */
/* ------------------------------------------------------------------------- */
KX_SCA_AddObjectActuator : : KX_SCA_AddObjectActuator ( SCA_IObject * gameobj ,
2008-07-12 12:10:27 +00:00
SCA_IObject * original ,
2002-10-12 11:37:38 +00:00
int time ,
SCA_IScene * scene ,
2009-05-23 03:24:15 +00:00
const float * linvel ,
2008-08-27 03:34:53 +00:00
bool linv_local ,
2009-05-23 03:24:15 +00:00
const float * angvel ,
2008-08-27 03:34:53 +00:00
bool angv_local ,
2002-10-12 11:37:38 +00:00
PyTypeObject * T )
:
SCA_IActuator ( gameobj , T ) ,
m_OriginalObject ( original ) ,
m_scene ( scene ) ,
2008-08-27 03:34:53 +00:00
m_localLinvFlag ( linv_local ) ,
m_localAngvFlag ( angv_local )
2002-10-12 11:37:38 +00:00
{
2009-05-23 03:24:15 +00:00
m_linear_velocity [ 0 ] = linvel [ 0 ] ;
m_linear_velocity [ 1 ] = linvel [ 1 ] ;
m_linear_velocity [ 2 ] = linvel [ 2 ] ;
m_angular_velocity [ 0 ] = angvel [ 0 ] ;
m_angular_velocity [ 1 ] = angvel [ 1 ] ;
m_angular_velocity [ 2 ] = angvel [ 2 ] ;
2008-07-12 12:10:27 +00:00
if ( m_OriginalObject )
m_OriginalObject - > RegisterActuator ( this ) ;
2002-10-12 11:37:38 +00:00
m_lastCreatedObject = NULL ;
m_timeProp = time ;
}
KX_SCA_AddObjectActuator : : ~ KX_SCA_AddObjectActuator ( )
{
2008-07-12 12:10:27 +00:00
if ( m_OriginalObject )
m_OriginalObject - > UnregisterActuator ( this ) ;
2002-10-12 11:37:38 +00:00
if ( m_lastCreatedObject )
m_lastCreatedObject - > Release ( ) ;
}
2004-10-16 11:41:50 +00:00
bool KX_SCA_AddObjectActuator : : Update ( )
2002-10-12 11:37:38 +00:00
{
2005-03-09 19:45:59 +00:00
//bool result = false; /*unused*/
2002-10-12 11:37:38 +00:00
bool bNegativeEvent = IsNegativeEvent ( ) ;
RemoveAllEvents ( ) ;
if ( bNegativeEvent ) return false ; // do nothing on negative events
2006-04-01 03:30:15 +00:00
InstantAddObject ( ) ;
2002-10-12 11:37:38 +00:00
2006-04-01 03:30:15 +00:00
2002-10-12 11:37:38 +00:00
return false ;
}
2006-04-01 03:30:15 +00:00
2002-10-12 11:37:38 +00:00
SCA_IObject * KX_SCA_AddObjectActuator : : GetLastCreatedObject ( ) const
{
return m_lastCreatedObject ;
}
CValue * KX_SCA_AddObjectActuator : : GetReplica ( )
{
KX_SCA_AddObjectActuator * replica = new KX_SCA_AddObjectActuator ( * this ) ;
if ( replica = = NULL )
return NULL ;
// this will copy properties and so on...
replica - > ProcessReplica ( ) ;
CValue : : AddDataToReplica ( replica ) ;
return replica ;
}
2008-07-12 12:10:27 +00:00
void KX_SCA_AddObjectActuator : : ProcessReplica ( )
{
if ( m_OriginalObject )
m_OriginalObject - > RegisterActuator ( this ) ;
m_lastCreatedObject = NULL ;
SCA_IActuator : : ProcessReplica ( ) ;
}
bool KX_SCA_AddObjectActuator : : UnlinkObject ( SCA_IObject * clientobj )
{
if ( clientobj = = m_OriginalObject )
{
// this object is being deleted, we cannot continue to track it.
m_OriginalObject = NULL ;
return true ;
}
return false ;
}
2002-10-12 11:37:38 +00:00
2008-07-19 07:45:19 +00:00
void KX_SCA_AddObjectActuator : : Relink ( GEN_Map < GEN_HashedPtr , void * > * obj_map )
{
void * * h_obj = ( * obj_map ) [ m_OriginalObject ] ;
if ( h_obj ) {
if ( m_OriginalObject )
m_OriginalObject - > UnregisterActuator ( this ) ;
m_OriginalObject = ( SCA_IObject * ) ( * h_obj ) ;
m_OriginalObject - > RegisterActuator ( this ) ;
}
}
2002-10-12 11:37:38 +00:00
/* ------------------------------------------------------------------------- */
/* Python functions */
/* ------------------------------------------------------------------------- */
/* Integration hooks ------------------------------------------------------- */
PyTypeObject KX_SCA_AddObjectActuator : : Type = {
2009-05-23 03:24:15 +00:00
PyObject_HEAD_INIT ( NULL )
2002-10-12 11:37:38 +00:00
0 ,
" KX_SCA_AddObjectActuator " ,
2009-05-23 03:24:15 +00:00
sizeof ( PyObjectPlus_Proxy ) ,
2002-10-12 11:37:38 +00:00
0 ,
2009-05-23 03:24:15 +00:00
py_base_dealloc ,
2002-10-12 11:37:38 +00:00
0 ,
0 ,
0 ,
0 ,
2009-05-23 03:24:15 +00:00
py_base_repr ,
0 , 0 , 0 , 0 , 0 , 0 ,
py_base_getattro ,
py_base_setattro ,
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
Methods
2002-10-12 11:37:38 +00:00
} ;
PyParentObject KX_SCA_AddObjectActuator : : Parents [ ] = {
2009-05-23 03:24:15 +00:00
& KX_SCA_AddObjectActuator : : Type ,
2002-10-12 11:37:38 +00:00
& SCA_IActuator : : Type ,
& SCA_ILogicBrick : : Type ,
& CValue : : Type ,
NULL
} ;
PyMethodDef KX_SCA_AddObjectActuator : : Methods [ ] = {
2009-05-23 03:24:15 +00:00
// ---> deprecated
2008-10-02 00:22:28 +00:00
{ " setTime " , ( PyCFunction ) KX_SCA_AddObjectActuator : : sPySetTime , METH_O , ( PY_METHODCHAR ) SetTime_doc } ,
{ " getTime " , ( PyCFunction ) KX_SCA_AddObjectActuator : : sPyGetTime , METH_NOARGS , ( PY_METHODCHAR ) GetTime_doc } ,
{ " getLinearVelocity " , ( PyCFunction ) KX_SCA_AddObjectActuator : : sPyGetLinearVelocity , METH_NOARGS , ( PY_METHODCHAR ) GetLinearVelocity_doc } ,
{ " setLinearVelocity " , ( PyCFunction ) KX_SCA_AddObjectActuator : : sPySetLinearVelocity , METH_VARARGS , ( PY_METHODCHAR ) SetLinearVelocity_doc } ,
{ " getAngularVelocity " , ( PyCFunction ) KX_SCA_AddObjectActuator : : sPyGetAngularVelocity , METH_NOARGS , ( PY_METHODCHAR ) GetAngularVelocity_doc } ,
{ " setAngularVelocity " , ( PyCFunction ) KX_SCA_AddObjectActuator : : sPySetAngularVelocity , METH_VARARGS , ( PY_METHODCHAR ) SetAngularVelocity_doc } ,
2008-08-27 03:34:53 +00:00
{ " getLastCreatedObject " , ( PyCFunction ) KX_SCA_AddObjectActuator : : sPyGetLastCreatedObject , METH_NOARGS , " getLastCreatedObject() : get the object handle to the last created object \n " } ,
{ " instantAddObject " , ( PyCFunction ) KX_SCA_AddObjectActuator : : sPyInstantAddObject , METH_NOARGS , " instantAddObject() : immediately add object without delay \n " } ,
2009-02-19 10:34:51 +00:00
{ " setObject " , ( PyCFunction ) KX_SCA_AddObjectActuator : : sPySetObject , METH_O , ( PY_METHODCHAR ) SetObject_doc } ,
{ " getObject " , ( PyCFunction ) KX_SCA_AddObjectActuator : : sPyGetObject , METH_VARARGS , ( PY_METHODCHAR ) GetObject_doc } ,
2002-10-12 11:37:38 +00:00
{ NULL , NULL } //Sentinel
} ;
2009-02-26 09:04:06 +00:00
PyAttributeDef KX_SCA_AddObjectActuator : : Attributes [ ] = {
2009-05-23 03:24:15 +00:00
KX_PYATTRIBUTE_RW_FUNCTION ( " object " , KX_SCA_AddObjectActuator , pyattr_get_object , pyattr_set_object ) ,
KX_PYATTRIBUTE_RO_FUNCTION ( " objectLastCreated " , KX_SCA_AddObjectActuator , pyattr_get_objectLastCreated ) ,
KX_PYATTRIBUTE_INT_RW ( " time " , 0 , 2000 , true , KX_SCA_AddObjectActuator , m_timeProp ) ,
KX_PYATTRIBUTE_FLOAT_ARRAY_RW ( " linearVelocity " , - FLT_MAX , FLT_MAX , KX_SCA_AddObjectActuator , m_linear_velocity , 3 ) ,
KX_PYATTRIBUTE_FLOAT_ARRAY_RW ( " angularVelocity " , - FLT_MAX , FLT_MAX , KX_SCA_AddObjectActuator , m_angular_velocity , 3 ) ,
2009-02-26 09:04:06 +00:00
{ NULL } //Sentinel
} ;
2002-10-12 11:37:38 +00:00
2009-05-23 03:24:15 +00:00
PyObject * KX_SCA_AddObjectActuator : : pyattr_get_object ( void * self , const struct KX_PYATTRIBUTE_DEF * attrdef )
2002-10-12 11:37:38 +00:00
{
2009-05-23 03:24:15 +00:00
KX_SCA_AddObjectActuator * actuator = static_cast < KX_SCA_AddObjectActuator * > ( self ) ;
if ( ! actuator - > m_OriginalObject )
Py_RETURN_NONE ;
else
return actuator - > m_OriginalObject - > GetProxy ( ) ;
2002-10-12 11:37:38 +00:00
}
2009-05-23 03:24:15 +00:00
int KX_SCA_AddObjectActuator : : pyattr_set_object ( void * self , const struct KX_PYATTRIBUTE_DEF * attrdef , PyObject * value )
{
KX_SCA_AddObjectActuator * actuator = static_cast < KX_SCA_AddObjectActuator * > ( self ) ;
KX_GameObject * gameobj ;
2009-02-19 10:34:51 +00:00
2009-05-23 03:24:15 +00:00
if ( ! ConvertPythonToGameObject ( value , & gameobj , true , " actuator.object = value: KX_SCA_AddObjectActuator " ) )
return 1 ; // ConvertPythonToGameObject sets the error
2009-02-19 10:34:51 +00:00
2009-05-23 03:24:15 +00:00
if ( actuator - > m_OriginalObject ! = NULL )
actuator - > m_OriginalObject - > UnregisterActuator ( actuator ) ;
2009-02-19 10:34:51 +00:00
2009-05-23 03:24:15 +00:00
actuator - > m_OriginalObject = ( SCA_IObject * ) gameobj ;
2009-02-19 10:34:51 +00:00
2009-05-23 03:24:15 +00:00
if ( actuator - > m_OriginalObject )
actuator - > m_OriginalObject - > RegisterActuator ( actuator ) ;
2009-02-19 10:34:51 +00:00
2009-05-23 03:24:15 +00:00
return 0 ;
}
PyObject * KX_SCA_AddObjectActuator : : pyattr_get_objectLastCreated ( void * self , const struct KX_PYATTRIBUTE_DEF * attrdef )
{
KX_SCA_AddObjectActuator * actuator = static_cast < KX_SCA_AddObjectActuator * > ( self ) ;
if ( ! actuator - > m_lastCreatedObject )
Py_RETURN_NONE ;
else
return actuator - > m_lastCreatedObject - > GetProxy ( ) ;
}
PyObject * KX_SCA_AddObjectActuator : : py_getattro ( PyObject * attr )
{
py_getattro_up ( SCA_IActuator ) ;
}
int KX_SCA_AddObjectActuator : : py_setattro ( PyObject * attr , PyObject * value )
{
py_setattro_up ( SCA_IActuator ) ;
2009-02-19 10:34:51 +00:00
}
2002-10-12 11:37:38 +00:00
/* 1. setObject */
2008-09-20 11:08:35 +00:00
const char KX_SCA_AddObjectActuator : : SetObject_doc [ ] =
2008-08-14 08:58:25 +00:00
" setObject(object) \n "
" \t - object: KX_GameObject, string or None \n "
2002-10-12 11:37:38 +00:00
" \t Sets the object that will be added. There has to be an object \n "
" \t of this name. If not, this function does nothing. \n " ;
2009-05-23 03:24:15 +00:00
PyObject * KX_SCA_AddObjectActuator : : PySetObject ( PyObject * value )
2008-08-14 08:58:25 +00:00
{
KX_GameObject * gameobj ;
2002-10-12 11:37:38 +00:00
2009-02-19 10:34:51 +00:00
ShowDeprecationWarning ( " setObject() " , " the object property " ) ;
2009-05-23 03:24:15 +00:00
if ( ! ConvertPythonToGameObject ( value , & gameobj , true , " actuator.setObject(value): KX_SCA_AddObjectActuator " ) )
2008-08-14 08:58:25 +00:00
return NULL ; // ConvertPythonToGameObject sets the error
2002-10-12 11:37:38 +00:00
2008-08-14 08:58:25 +00:00
if ( m_OriginalObject ! = NULL )
m_OriginalObject - > UnregisterActuator ( this ) ;
m_OriginalObject = ( SCA_IObject * ) gameobj ;
if ( m_OriginalObject )
m_OriginalObject - > RegisterActuator ( this ) ;
Py_RETURN_NONE ;
2002-10-12 11:37:38 +00:00
}
/* 2. setTime */
2008-09-20 11:08:35 +00:00
const char KX_SCA_AddObjectActuator : : SetTime_doc [ ] =
2002-10-12 11:37:38 +00:00
" setTime(duration) \n "
" \t - duration: integer \n "
" \t Sets the lifetime of the object that will be added, in frames. \n "
" \t If the duration is negative, it is set to 0. \n " ;
2009-05-23 03:24:15 +00:00
PyObject * KX_SCA_AddObjectActuator : : PySetTime ( PyObject * value )
2002-10-12 11:37:38 +00:00
{
2009-05-23 03:24:15 +00:00
ShowDeprecationWarning ( " setTime() " , " the time property " ) ;
2008-08-27 03:34:53 +00:00
int deltatime = PyInt_AsLong ( value ) ;
if ( deltatime = = - 1 & & PyErr_Occurred ( ) ) {
PyErr_SetString ( PyExc_TypeError , " expected an int " ) ;
2002-10-12 11:37:38 +00:00
return NULL ;
2008-08-27 03:34:53 +00:00
}
2002-10-12 11:37:38 +00:00
m_timeProp = deltatime ;
if ( m_timeProp < 0 ) m_timeProp = 0 ;
2008-08-27 03:34:53 +00:00
Py_RETURN_NONE ;
2002-10-12 11:37:38 +00:00
}
/* 3. getTime */
2008-09-20 11:08:35 +00:00
const char KX_SCA_AddObjectActuator : : GetTime_doc [ ] =
2009-05-23 03:24:15 +00:00
" getTime() \n "
2002-10-12 11:37:38 +00:00
" \t Returns the lifetime of the object that will be added. \n " ;
2009-05-23 03:24:15 +00:00
PyObject * KX_SCA_AddObjectActuator : : PyGetTime ( )
2002-10-12 11:37:38 +00:00
{
2009-05-23 03:24:15 +00:00
ShowDeprecationWarning ( " getTime() " , " the time property " ) ;
2002-10-12 11:37:38 +00:00
return PyInt_FromLong ( m_timeProp ) ;
}
/* 4. getObject */
2008-09-20 11:08:35 +00:00
const char KX_SCA_AddObjectActuator : : GetObject_doc [ ] =
2008-08-14 08:58:25 +00:00
" getObject(name_only = 1) \n "
" name_only - optional arg, when true will return the KX_GameObject rather then its name \n "
2002-10-12 11:37:38 +00:00
" \t Returns the name of the object that will be added. \n " ;
2009-05-23 03:24:15 +00:00
PyObject * KX_SCA_AddObjectActuator : : PyGetObject ( PyObject * args )
2002-10-12 11:37:38 +00:00
{
2008-08-14 08:58:25 +00:00
int ret_name_only = 1 ;
2009-02-19 10:34:51 +00:00
ShowDeprecationWarning ( " getObject() " , " the object property " ) ;
2009-05-23 03:24:15 +00:00
if ( ! PyArg_ParseTuple ( args , " |i:getObject " , & ret_name_only ) )
2008-08-14 08:58:25 +00:00
return NULL ;
2004-09-19 01:33:08 +00:00
if ( ! m_OriginalObject )
2008-08-14 08:58:25 +00:00
Py_RETURN_NONE ;
if ( ret_name_only )
return PyString_FromString ( m_OriginalObject - > GetName ( ) ) ;
else
2009-05-23 03:24:15 +00:00
return m_OriginalObject - > GetProxy ( ) ;
2002-10-12 11:37:38 +00:00
}
/* 5. getLinearVelocity */
2008-09-20 11:08:35 +00:00
const char KX_SCA_AddObjectActuator : : GetLinearVelocity_doc [ ] =
2002-10-12 11:37:38 +00:00
" GetLinearVelocity() \n "
" \t Returns the linear velocity that will be assigned to \n "
" \t the created object. \n " ;
2009-05-23 03:24:15 +00:00
PyObject * KX_SCA_AddObjectActuator : : PyGetLinearVelocity ( )
2002-10-12 11:37:38 +00:00
{
2009-05-23 03:24:15 +00:00
ShowDeprecationWarning ( " getLinearVelocity() " , " the linearVelocity property " ) ;
2002-10-12 11:37:38 +00:00
PyObject * retVal = PyList_New ( 3 ) ;
2008-08-27 03:34:53 +00:00
PyList_SET_ITEM ( retVal , 0 , PyFloat_FromDouble ( m_linear_velocity [ 0 ] ) ) ;
PyList_SET_ITEM ( retVal , 1 , PyFloat_FromDouble ( m_linear_velocity [ 1 ] ) ) ;
PyList_SET_ITEM ( retVal , 2 , PyFloat_FromDouble ( m_linear_velocity [ 2 ] ) ) ;
2002-10-12 11:37:38 +00:00
return retVal ;
}
/* 6. setLinearVelocity */
2008-09-20 11:08:35 +00:00
const char KX_SCA_AddObjectActuator : : SetLinearVelocity_doc [ ] =
2002-10-12 11:37:38 +00:00
" setLinearVelocity(vx, vy, vz) \n "
" \t - vx: float \n "
" \t - vy: float \n "
" \t - vz: float \n "
2008-08-27 03:34:53 +00:00
" \t - local: bool \n "
2002-10-12 11:37:38 +00:00
" \t Assign this velocity to the created object. \n " ;
2009-05-23 03:24:15 +00:00
PyObject * KX_SCA_AddObjectActuator : : PySetLinearVelocity ( PyObject * args )
2002-10-12 11:37:38 +00:00
{
2009-05-23 03:24:15 +00:00
ShowDeprecationWarning ( " setLinearVelocity() " , " the linearVelocity property " ) ;
2002-10-12 11:37:38 +00:00
float vecArg [ 3 ] ;
2009-05-23 03:24:15 +00:00
if ( ! PyArg_ParseTuple ( args , " fff:setLinearVelocity " , & vecArg [ 0 ] , & vecArg [ 1 ] , & vecArg [ 2 ] ) )
2002-10-12 11:37:38 +00:00
return NULL ;
2009-05-23 03:24:15 +00:00
m_linear_velocity [ 0 ] = vecArg [ 0 ] ;
m_linear_velocity [ 1 ] = vecArg [ 1 ] ;
m_linear_velocity [ 2 ] = vecArg [ 2 ] ;
2008-08-27 03:34:53 +00:00
Py_RETURN_NONE ;
}
/* 7. getAngularVelocity */
2008-09-20 11:08:35 +00:00
const char KX_SCA_AddObjectActuator : : GetAngularVelocity_doc [ ] =
2008-08-27 03:34:53 +00:00
" GetAngularVelocity() \n "
" \t Returns the angular velocity that will be assigned to \n "
" \t the created object. \n " ;
2009-05-23 03:24:15 +00:00
PyObject * KX_SCA_AddObjectActuator : : PyGetAngularVelocity ( )
2008-08-27 03:34:53 +00:00
{
2009-05-23 03:24:15 +00:00
ShowDeprecationWarning ( " getAngularVelocity() " , " the angularVelocity property " ) ;
2008-08-27 03:34:53 +00:00
PyObject * retVal = PyList_New ( 3 ) ;
PyList_SET_ITEM ( retVal , 0 , PyFloat_FromDouble ( m_angular_velocity [ 0 ] ) ) ;
PyList_SET_ITEM ( retVal , 1 , PyFloat_FromDouble ( m_angular_velocity [ 1 ] ) ) ;
PyList_SET_ITEM ( retVal , 2 , PyFloat_FromDouble ( m_angular_velocity [ 2 ] ) ) ;
return retVal ;
}
/* 8. setAngularVelocity */
2008-09-20 11:08:35 +00:00
const char KX_SCA_AddObjectActuator : : SetAngularVelocity_doc [ ] =
2008-08-27 03:34:53 +00:00
" setAngularVelocity(vx, vy, vz) \n "
" \t - vx: float \n "
" \t - vy: float \n "
" \t - vz: float \n "
" \t - local: bool \n "
" \t Assign this angular velocity to the created object. \n " ;
2009-05-23 03:24:15 +00:00
PyObject * KX_SCA_AddObjectActuator : : PySetAngularVelocity ( PyObject * args )
2008-08-27 03:34:53 +00:00
{
2009-05-23 03:24:15 +00:00
ShowDeprecationWarning ( " setAngularVelocity() " , " the angularVelocity property " ) ;
2008-08-27 03:34:53 +00:00
float vecArg [ 3 ] ;
2009-05-23 03:24:15 +00:00
if ( ! PyArg_ParseTuple ( args , " fff:setAngularVelocity " , & vecArg [ 0 ] , & vecArg [ 1 ] , & vecArg [ 2 ] ) )
2008-08-27 03:34:53 +00:00
return NULL ;
2009-05-23 03:24:15 +00:00
m_angular_velocity [ 0 ] = vecArg [ 0 ] ;
m_angular_velocity [ 1 ] = vecArg [ 1 ] ;
m_angular_velocity [ 2 ] = vecArg [ 2 ] ;
2008-08-27 03:34:53 +00:00
Py_RETURN_NONE ;
2002-10-12 11:37:38 +00:00
}
2006-04-01 03:30:15 +00:00
void KX_SCA_AddObjectActuator : : InstantAddObject ( )
{
if ( m_OriginalObject )
{
// Add an identical object, with properties inherited from the original object
// Now it needs to be added to the current scene.
SCA_IObject * replica = m_scene - > AddReplicaObject ( m_OriginalObject , GetParent ( ) , m_timeProp ) ;
KX_GameObject * game_obj = static_cast < KX_GameObject * > ( replica ) ;
2009-05-23 03:24:15 +00:00
game_obj - > setLinearVelocity ( m_linear_velocity , m_localLinvFlag ) ;
2008-08-27 03:34:53 +00:00
game_obj - > setAngularVelocity ( m_angular_velocity , m_localAngvFlag ) ;
game_obj - > ResolveCombinedVelocities ( m_linear_velocity , m_angular_velocity , m_localLinvFlag , m_localAngvFlag ) ;
2006-04-01 03:30:15 +00:00
// keep a copy of the last object, to allow python scripters to change it
if ( m_lastCreatedObject )
2006-05-22 21:03:43 +00:00
{
//careful with destruction, it might still have outstanding collision callbacks
m_scene - > DelayedReleaseObject ( m_lastCreatedObject ) ;
2006-04-01 03:30:15 +00:00
m_lastCreatedObject - > Release ( ) ;
2006-05-22 21:03:43 +00:00
}
2006-04-01 03:30:15 +00:00
m_lastCreatedObject = replica ;
m_lastCreatedObject - > AddRef ( ) ;
2008-03-01 19:46:50 +00:00
// finished using replica? then release it
replica - > Release ( ) ;
2006-04-01 03:30:15 +00:00
}
}
2009-05-23 03:24:15 +00:00
PyObject * KX_SCA_AddObjectActuator : : PyInstantAddObject ( )
2006-04-01 03:30:15 +00:00
{
InstantAddObject ( ) ;
2008-08-27 03:34:53 +00:00
Py_RETURN_NONE ;
2006-04-01 03:30:15 +00:00
}
2002-10-12 11:37:38 +00:00
/* 7. GetLastCreatedObject */
2008-09-20 11:08:35 +00:00
const char KX_SCA_AddObjectActuator : : GetLastCreatedObject_doc [ ] =
2002-10-12 11:37:38 +00:00
" getLastCreatedObject() \n "
" \t Return the last created object. \n " ;
2009-05-23 03:24:15 +00:00
PyObject * KX_SCA_AddObjectActuator : : PyGetLastCreatedObject ( )
2002-10-12 11:37:38 +00:00
{
2009-05-23 03:24:15 +00:00
ShowDeprecationWarning ( " getLastCreatedObject() " , " the objectLastCreated property " ) ;
2002-10-12 11:37:38 +00:00
SCA_IObject * result = this - > GetLastCreatedObject ( ) ;
2008-08-25 09:52:38 +00:00
// if result->GetSGNode() is NULL
// it means the object has ended, The BGE python api crashes in many places if the object is returned.
if ( result & & ( static_cast < KX_GameObject * > ( result ) ) - > GetSGNode ( ) )
2002-10-12 11:37:38 +00:00
{
2009-05-23 03:24:15 +00:00
return result - > GetProxy ( ) ;
2002-10-12 11:37:38 +00:00
}
// don't return NULL to python anymore, it gives trouble in the scripts
2008-08-27 03:34:53 +00:00
Py_RETURN_NONE ;
2002-10-12 11:37:38 +00:00
}