rename and negate DISABLE_PYTHON --> WITH_PYTHON
[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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 WITH_PYTHON
41
42 /* ------------------------------------------------------------------------- */
43 /* Python functions                                                          */
44 /* ------------------------------------------------------------------------- */
45
46 /* Integration hooks ------------------------------------------------------- */
47
48 PyTypeObject KX_SCA_DynamicActuator::Type = {
49         PyVarObject_HEAD_INIT(NULL, 0)
50         "KX_SCA_DynamicActuator",
51         sizeof(PyObjectPlus_Proxy),
52         0,
53         py_base_dealloc,
54         0,
55         0,
56         0,
57         0,
58         py_base_repr,
59         0,0,0,0,0,0,0,0,0,
60         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
61         0,0,0,0,0,0,0,
62         Methods,
63         0,
64         0,
65         &SCA_IActuator::Type,
66         0,0,0,0,0,0,
67         py_base_new
68 };
69
70 PyMethodDef KX_SCA_DynamicActuator::Methods[] = {
71         {NULL,NULL} //Sentinel
72 };
73
74 PyAttributeDef KX_SCA_DynamicActuator::Attributes[] = {
75         KX_PYATTRIBUTE_SHORT_RW("mode",0,4,false,KX_SCA_DynamicActuator,m_dyn_operation),
76         KX_PYATTRIBUTE_FLOAT_RW("mass",0.0,FLT_MAX,KX_SCA_DynamicActuator,m_setmass),
77         { NULL }        //Sentinel
78 };
79
80 #endif // WITH_PYTHON
81
82 /* ------------------------------------------------------------------------- */
83 /* Native functions                                                          */
84 /* ------------------------------------------------------------------------- */
85
86 KX_SCA_DynamicActuator::KX_SCA_DynamicActuator(SCA_IObject *gameobj,
87                                                                                                            short dyn_operation,
88                                                                                                            float setmass) :
89
90         SCA_IActuator(gameobj, KX_ACT_DYNAMIC),
91         m_dyn_operation(dyn_operation),
92         m_setmass(setmass)
93 {
94 } /* End of constructor */
95
96
97 KX_SCA_DynamicActuator::~KX_SCA_DynamicActuator()
98
99         // there's nothing to be done here, really....
100 } /* end of destructor */
101
102
103
104 bool KX_SCA_DynamicActuator::Update()
105 {
106         // bool result = false; /*unused*/
107         KX_GameObject *obj = (KX_GameObject*) GetParent();
108         bool bNegativeEvent = IsNegativeEvent();
109         KX_IPhysicsController* controller;
110         RemoveAllEvents();
111
112         if (bNegativeEvent)
113                 return false; // do nothing on negative events
114         
115         if (!obj)
116                 return false; // object not accessible, shouldnt happen
117         controller = obj->GetPhysicsController();
118         if (!controller)
119                 return false;   // no physic object
120
121         switch (m_dyn_operation)
122         {
123                 case 0:                 
124                         obj->RestoreDynamics(); 
125                         break;
126                 case 1:
127                         obj->SuspendDynamics();
128                         break;
129                 case 2:
130                         controller->setRigidBody(true); 
131                         break;
132                 case 3:
133                         controller->setRigidBody(false);
134                         break;
135                 case 4:
136                         controller->SetMass(m_setmass);
137                         break;
138         }
139
140         return false;
141 }
142
143
144
145 CValue* KX_SCA_DynamicActuator::GetReplica()
146 {
147         KX_SCA_DynamicActuator* replica = 
148                 new KX_SCA_DynamicActuator(*this);
149
150         if (replica == NULL)
151                 return NULL;
152
153         replica->ProcessReplica();
154         return replica;
155 };
156
157
158 /* eof */