remove python2.x support
[blender.git] / source / gameengine / Ketsji / KXNetwork / KX_NetworkMessageActuator.cpp
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  * Ketsji Logic Extenstion: Network Message Actuator generic implementation
29  */
30
31 #include "NG_NetworkScene.h"
32 #include "KX_NetworkMessageActuator.h"
33
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37
38 KX_NetworkMessageActuator::KX_NetworkMessageActuator(
39         SCA_IObject* gameobj,           // the actuator controlling object
40         NG_NetworkScene* networkscene,  // needed for replication
41         const STR_String &toPropName,
42         const STR_String &subject,
43         int bodyType,
44         const STR_String &body) :
45         SCA_IActuator(gameobj),
46         m_networkscene(networkscene),
47         m_toPropName(toPropName),
48         m_subject(subject),
49         m_bPropBody(bodyType),
50         m_body(body)
51 {
52 }
53
54 KX_NetworkMessageActuator::~KX_NetworkMessageActuator()
55 {
56 }
57
58 // returns true if the actuators needs to be running over several frames
59 bool KX_NetworkMessageActuator::Update()
60 {
61         //printf("update messageactuator\n");
62         bool bNegativeEvent = IsNegativeEvent();
63         RemoveAllEvents();
64
65         if (bNegativeEvent) {
66                 return false; // do nothing on negative events
67                 //printf("messageactuator false event\n");
68         }
69         //printf("messageactuator true event\n");
70
71         if (m_bPropBody) // ACT_MESG_PROP in DNA_actuator_types.h
72         {
73                 m_networkscene->SendMessage(
74                         m_toPropName,
75                         GetParent()->GetName(),
76                         m_subject,
77                         GetParent()->GetPropertyText(m_body));
78         } else
79         {
80                 m_networkscene->SendMessage(
81                         m_toPropName,
82                         GetParent()->GetName(),
83                         m_subject,
84                         m_body);
85         }
86         return false;
87 }
88
89 CValue* KX_NetworkMessageActuator::GetReplica()
90 {
91         KX_NetworkMessageActuator* replica =
92             new KX_NetworkMessageActuator(*this);
93         replica->ProcessReplica();
94
95         return replica;
96 }
97
98 /* -------------------------------------------------------------------- */
99 /* Python interface --------------------------------------------------- */
100 /* -------------------------------------------------------------------- */
101
102 /* Integration hooks -------------------------------------------------- */
103 PyTypeObject KX_NetworkMessageActuator::Type = {
104         PyVarObject_HEAD_INIT(NULL, 0)
105         "KX_NetworkMessageActuator",
106         sizeof(PyObjectPlus_Proxy),
107         0,
108         py_base_dealloc,
109         0,
110         0,
111         0,
112         0,
113         py_base_repr,
114         0,0,0,0,0,0,0,0,0,
115         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
116         0,0,0,0,0,0,0,
117         Methods,
118         0,
119         0,
120         &SCA_IActuator::Type,
121         0,0,0,0,0,0,
122         py_base_new
123 };
124
125 PyMethodDef KX_NetworkMessageActuator::Methods[] = {
126         // Deprecated ----->
127         {"setToPropName", (PyCFunction)
128                 KX_NetworkMessageActuator::sPySetToPropName, METH_VARARGS},
129         {"setSubject", (PyCFunction)
130                 KX_NetworkMessageActuator::sPySetSubject, METH_VARARGS},
131         {"setBodyType", (PyCFunction)
132                 KX_NetworkMessageActuator::sPySetBodyType, METH_VARARGS},
133         {"setBody", (PyCFunction)
134                 KX_NetworkMessageActuator::sPySetBody, METH_VARARGS},
135         // <-----
136         {NULL,NULL} // Sentinel
137 };
138
139 PyAttributeDef KX_NetworkMessageActuator::Attributes[] = {
140         KX_PYATTRIBUTE_STRING_RW("propName", 0, 100, false, KX_NetworkMessageActuator, m_toPropName),
141         KX_PYATTRIBUTE_STRING_RW("subject", 0, 100, false, KX_NetworkMessageActuator, m_subject),
142         KX_PYATTRIBUTE_BOOL_RW("usePropBody", KX_NetworkMessageActuator, m_bPropBody),
143         KX_PYATTRIBUTE_STRING_RW("body", 0, 16384, false, KX_NetworkMessageActuator, m_body),
144         { NULL }        //Sentinel
145 };
146
147 // Deprecated ----->
148 // 1. SetToPropName
149 PyObject* KX_NetworkMessageActuator::PySetToPropName(
150         PyObject* args,
151         PyObject* kwds)
152 {
153         ShowDeprecationWarning("setToProp()", "the propName property");
154     char* ToPropName;
155
156         if (PyArg_ParseTuple(args, "s:setToPropName", &ToPropName)) {
157              m_toPropName = ToPropName;
158         }
159         else {
160                 return NULL;
161         }
162
163         Py_RETURN_NONE;
164 }
165
166 // 2. SetSubject
167 PyObject* KX_NetworkMessageActuator::PySetSubject(
168         PyObject* args,
169         PyObject* kwds)
170 {
171         ShowDeprecationWarning("setSubject()", "the subject property");
172     char* Subject;
173
174         if (PyArg_ParseTuple(args, "s:setSubject", &Subject)) {
175              m_subject = Subject;
176         }
177         else {
178                 return NULL;
179         }
180         
181         Py_RETURN_NONE;
182 }
183
184 // 3. SetBodyType
185 PyObject* KX_NetworkMessageActuator::PySetBodyType(
186         PyObject* args,
187         PyObject* kwds)
188 {
189         ShowDeprecationWarning("setBodyType()", "the usePropBody property");
190     int BodyType;
191
192         if (PyArg_ParseTuple(args, "i:setBodyType", &BodyType)) {
193                 m_bPropBody = (BodyType != 0);
194         }
195         else {
196                 return NULL;
197         }
198
199         Py_RETURN_NONE;
200 }
201
202 // 4. SetBody
203 PyObject* KX_NetworkMessageActuator::PySetBody(
204         PyObject* args,
205         PyObject* kwds)
206 {
207         ShowDeprecationWarning("setBody()", "the body property");
208     char* Body;
209
210         if (PyArg_ParseTuple(args, "s:setBody", &Body)) {
211              m_body = Body;
212         }
213         else {
214                 return NULL;
215         }
216
217         Py_RETURN_NONE;
218 }
219
220 // <----- Deprecated