add missing files after merging
[blender.git] / source / gameengine / Ketsji / KX_SCA_DynamicActuator.cpp
1 /** \file gameengine/Ketsji/KX_SCA_DynamicActuator.cpp
2  *  \ingroup ketsji
3  */
4 //
5 // Adjust dynamics settins for this object
6 //
7 // $Id$
8 //
9 // ***** BEGIN GPL LICENSE BLOCK *****
10 //
11 // This program is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License
13 // as published by the Free Software Foundation; either version 2
14 // of the License, or (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software Foundation,
23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 // The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
26 // All rights reserved.
27 //
28 // The Original Code is: all of this file.
29 //
30 // Contributor(s): none yet.
31 //
32 // ***** END GPL LICENSE BLOCK *****
33
34 //
35 // Previously existed as:
36
37 // \source\gameengine\GameLogic\SCA_DynamicActuator.cpp
38
39 // Please look here for revision history.
40
41 #include "KX_SCA_DynamicActuator.h"
42
43 #ifdef WITH_PYTHON
44
45 /* ------------------------------------------------------------------------- */
46 /* Python functions                                                          */
47 /* ------------------------------------------------------------------------- */
48
49 /* Integration hooks ------------------------------------------------------- */
50
51 PyTypeObject KX_SCA_DynamicActuator::Type = {
52         PyVarObject_HEAD_INIT(NULL, 0)
53         "KX_SCA_DynamicActuator",
54         sizeof(PyObjectPlus_Proxy),
55         0,
56         py_base_dealloc,
57         0,
58         0,
59         0,
60         0,
61         py_base_repr,
62         0,0,0,0,0,0,0,0,0,
63         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
64         0,0,0,0,0,0,0,
65         Methods,
66         0,
67         0,
68         &SCA_IActuator::Type,
69         0,0,0,0,0,0,
70         py_base_new
71 };
72
73 PyMethodDef KX_SCA_DynamicActuator::Methods[] = {
74         {NULL,NULL} //Sentinel
75 };
76
77 PyAttributeDef KX_SCA_DynamicActuator::Attributes[] = {
78         KX_PYATTRIBUTE_SHORT_RW("mode",0,4,false,KX_SCA_DynamicActuator,m_dyn_operation),
79         KX_PYATTRIBUTE_FLOAT_RW("mass",0.0,FLT_MAX,KX_SCA_DynamicActuator,m_setmass),
80         { NULL }        //Sentinel
81 };
82
83 #endif // WITH_PYTHON
84
85 /* ------------------------------------------------------------------------- */
86 /* Native functions                                                          */
87 /* ------------------------------------------------------------------------- */
88
89 KX_SCA_DynamicActuator::KX_SCA_DynamicActuator(SCA_IObject *gameobj,
90                                                                                                            short dyn_operation,
91                                                                                                            float setmass) :
92
93         SCA_IActuator(gameobj, KX_ACT_DYNAMIC),
94         m_dyn_operation(dyn_operation),
95         m_setmass(setmass)
96 {
97 } /* End of constructor */
98
99
100 KX_SCA_DynamicActuator::~KX_SCA_DynamicActuator()
101
102         // there's nothing to be done here, really....
103 } /* end of destructor */
104
105
106
107 bool KX_SCA_DynamicActuator::Update()
108 {
109         // bool result = false; /*unused*/
110         KX_GameObject *obj = (KX_GameObject*) GetParent();
111         bool bNegativeEvent = IsNegativeEvent();
112         KX_IPhysicsController* controller;
113         RemoveAllEvents();
114
115         if (bNegativeEvent)
116                 return false; // do nothing on negative events
117         
118         if (!obj)
119                 return false; // object not accessible, shouldnt happen
120         controller = obj->GetPhysicsController();
121         if (!controller)
122                 return false;   // no physic object
123
124         switch (m_dyn_operation)
125         {
126                 case 0:                 
127                         obj->RestoreDynamics(); 
128                         break;
129                 case 1:
130                         obj->SuspendDynamics();
131                         break;
132                 case 2:
133                         controller->setRigidBody(true); 
134                         break;
135                 case 3:
136                         controller->setRigidBody(false);
137                         break;
138                 case 4:
139                         controller->SetMass(m_setmass);
140                         break;
141         }
142
143         return false;
144 }
145
146
147
148 CValue* KX_SCA_DynamicActuator::GetReplica()
149 {
150         KX_SCA_DynamicActuator* replica = 
151                 new KX_SCA_DynamicActuator(*this);
152
153         if (replica == NULL)
154                 return NULL;
155
156         replica->ProcessReplica();
157         return replica;
158 };
159
160
161 /* eof */