removing files that should not be in blender2.5, added (by mistake?) r19226
[blender.git] / source / gameengine / Ketsji / KX_SCA_DynamicActuator.cpp
1 //
2 // Adjust dynamics settins for this object
3 //
4 // $Id$
5 //
6 // ***** BEGIN GPL LICENSE BLOCK *****
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License
10 // as published by the Free Software Foundation; either version 2
11 // of the License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software Foundation,
20 // Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21 //
22 // The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23 // All rights reserved.
24 //
25 // The Original Code is: all of this file.
26 //
27 // Contributor(s): none yet.
28 //
29 // ***** END GPL LICENSE BLOCK *****
30
31 //
32 // Previously existed as:
33
34 // \source\gameengine\GameLogic\SCA_DynamicActuator.cpp
35
36 // Please look here for revision history.
37
38 #include "KX_SCA_DynamicActuator.h"
39
40 #ifdef HAVE_CONFIG_H
41 #include <config.h>
42 #endif
43
44 /* ------------------------------------------------------------------------- */
45 /* Python functions                                                          */
46 /* ------------------------------------------------------------------------- */
47
48 /* Integration hooks ------------------------------------------------------- */
49
50         PyTypeObject 
51
52 KX_SCA_DynamicActuator::Type = {
53 #if (PY_VERSION_HEX >= 0x02060000)
54         PyVarObject_HEAD_INIT(NULL, 0)
55 #else
56         /* python 2.5 and below */
57         PyObject_HEAD_INIT( NULL )  /* required py macro */
58         0,                          /* ob_size */
59 #endif
60         "KX_SCA_DynamicActuator",
61         sizeof(PyObjectPlus_Proxy),
62         0,
63         py_base_dealloc,
64         0,
65         0,
66         0,
67         0,
68         py_base_repr,
69         0,0,0,0,0,0,
70         py_base_getattro,
71         py_base_setattro,
72         0,0,0,0,0,0,0,0,0,
73         Methods
74 };
75
76 PyParentObject KX_SCA_DynamicActuator::Parents[] = {
77         &KX_SCA_DynamicActuator::Type,
78         &SCA_IActuator::Type,
79         &SCA_ILogicBrick::Type,
80         &CValue::Type,
81         NULL
82 };
83
84
85 PyMethodDef KX_SCA_DynamicActuator::Methods[] = {
86         // ---> deprecated
87         KX_PYMETHODTABLE(KX_SCA_DynamicActuator, setOperation),
88         KX_PYMETHODTABLE(KX_SCA_DynamicActuator, getOperation),
89         {NULL,NULL} //Sentinel
90 };
91
92 PyAttributeDef KX_SCA_DynamicActuator::Attributes[] = {
93         KX_PYATTRIBUTE_SHORT_RW("mode",0,4,false,KX_SCA_DynamicActuator,m_dyn_operation),
94         KX_PYATTRIBUTE_FLOAT_RW("mass",0.0,FLT_MAX,KX_SCA_DynamicActuator,m_setmass),
95         { NULL }        //Sentinel
96 };
97
98
99 PyObject* KX_SCA_DynamicActuator::py_getattro(PyObject *attr)
100 {
101         py_getattro_up(SCA_IActuator);
102 }
103
104 PyObject* KX_SCA_DynamicActuator::py_getattro_dict() {
105         py_getattro_dict_up(SCA_IActuator);
106 }
107
108 int KX_SCA_DynamicActuator::py_setattro(PyObject *attr, PyObject* value)
109 {
110         py_setattro_up(SCA_IActuator);
111 }
112
113
114 /* 1. setOperation */
115 KX_PYMETHODDEF_DOC(KX_SCA_DynamicActuator, setOperation,
116 "setOperation(operation?)\n"
117 "\t - operation? : type of dynamic operation\n"
118 "\t                0 = restore dynamics\n"
119 "\t                1 = disable dynamics\n"
120 "\t                2 = enable rigid body\n"
121 "\t                3 = disable rigid body\n"
122 "Change the dynamic status of the parent object.\n")
123 {
124         ShowDeprecationWarning("setOperation()", "the mode property");
125         int dyn_operation;
126         
127         if (!PyArg_ParseTuple(args, "i:setOperation", &dyn_operation))
128         {
129                 return NULL;    
130         }
131         if (dyn_operation <0 || dyn_operation>3) {
132                 PyErr_SetString(PyExc_IndexError, "Dynamic Actuator's setOperation() range must be between 0 and 3");
133                 return NULL;
134         }
135         m_dyn_operation= dyn_operation;
136         Py_RETURN_NONE;
137 }
138
139 KX_PYMETHODDEF_DOC(KX_SCA_DynamicActuator, getOperation,
140 "getOperation() -> integer\n"
141 "Returns the operation type of this actuator.\n"
142 )
143 {
144         ShowDeprecationWarning("getOperation()", "the mode property");
145         return PyInt_FromLong((long)m_dyn_operation);
146 }
147
148
149 /* ------------------------------------------------------------------------- */
150 /* Native functions                                                          */
151 /* ------------------------------------------------------------------------- */
152
153 KX_SCA_DynamicActuator::KX_SCA_DynamicActuator(SCA_IObject *gameobj,
154                                                                                                            short dyn_operation,
155                                                                                                            float setmass,
156                                                                                                            PyTypeObject* T) : 
157
158         SCA_IActuator(gameobj, T),
159         m_dyn_operation(dyn_operation),
160         m_setmass(setmass)
161 {
162 } /* End of constructor */
163
164
165 KX_SCA_DynamicActuator::~KX_SCA_DynamicActuator()
166
167         // there's nothing to be done here, really....
168 } /* end of destructor */
169
170
171
172 bool KX_SCA_DynamicActuator::Update()
173 {
174         // bool result = false; /*unused*/
175         KX_GameObject *obj = (KX_GameObject*) GetParent();
176         bool bNegativeEvent = IsNegativeEvent();
177         KX_IPhysicsController* controller;
178         RemoveAllEvents();
179
180         if (bNegativeEvent)
181                 return false; // do nothing on negative events
182         
183         if (!obj)
184                 return false; // object not accessible, shouldnt happen
185         controller = obj->GetPhysicsController();
186         if (!controller)
187                 return false;   // no physic object
188
189         switch (m_dyn_operation)
190         {
191                 case 0:                 
192                         obj->RestoreDynamics(); 
193                         break;
194                 case 1:
195                         obj->SuspendDynamics();
196                         break;
197                 case 2:
198                         controller->setRigidBody(true); 
199                         break;
200                 case 3:
201                         controller->setRigidBody(false);
202                         break;
203                 case 4:
204                         controller->SetMass(m_setmass);
205                         break;
206         }
207
208         return false;
209 }
210
211
212
213 CValue* KX_SCA_DynamicActuator::GetReplica()
214 {
215         KX_SCA_DynamicActuator* replica = 
216                 new KX_SCA_DynamicActuator(*this);
217
218         if (replica == NULL)
219                 return NULL;
220
221         replica->ProcessReplica();
222         return replica;
223 };
224
225
226 /* eof */