rename and negate DISABLE_PYTHON --> WITH_PYTHON
[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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 KX_NetworkMessageActuator::KX_NetworkMessageActuator(
35         SCA_IObject* gameobj,           // the actuator controlling object
36         NG_NetworkScene* networkscene,  // needed for replication
37         const STR_String &toPropName,
38         const STR_String &subject,
39         int bodyType,
40         const STR_String &body) :
41         SCA_IActuator(gameobj, KX_ACT_MESSAGE),
42         m_networkscene(networkscene),
43         m_toPropName(toPropName),
44         m_subject(subject),
45         m_bPropBody(bodyType),
46         m_body(body)
47 {
48 }
49
50 KX_NetworkMessageActuator::~KX_NetworkMessageActuator()
51 {
52 }
53
54 // returns true if the actuators needs to be running over several frames
55 bool KX_NetworkMessageActuator::Update()
56 {
57         //printf("update messageactuator\n");
58         bool bNegativeEvent = IsNegativeEvent();
59         RemoveAllEvents();
60
61         if (bNegativeEvent) {
62                 return false; // do nothing on negative events
63                 //printf("messageactuator false event\n");
64         }
65         //printf("messageactuator true event\n");
66
67         if (m_bPropBody) // ACT_MESG_PROP in DNA_actuator_types.h
68         {
69                 m_networkscene->SendMessage(
70                         m_toPropName,
71                         GetParent()->GetName(),
72                         m_subject,
73                         GetParent()->GetPropertyText(m_body));
74         } else
75         {
76                 m_networkscene->SendMessage(
77                         m_toPropName,
78                         GetParent()->GetName(),
79                         m_subject,
80                         m_body);
81         }
82         return false;
83 }
84
85 CValue* KX_NetworkMessageActuator::GetReplica()
86 {
87         KX_NetworkMessageActuator* replica =
88             new KX_NetworkMessageActuator(*this);
89         replica->ProcessReplica();
90
91         return replica;
92 }
93
94 #ifdef WITH_PYTHON
95
96 /* -------------------------------------------------------------------- */
97 /* Python interface --------------------------------------------------- */
98 /* -------------------------------------------------------------------- */
99
100 /* Integration hooks -------------------------------------------------- */
101 PyTypeObject KX_NetworkMessageActuator::Type = {
102         PyVarObject_HEAD_INIT(NULL, 0)
103         "KX_NetworkMessageActuator",
104         sizeof(PyObjectPlus_Proxy),
105         0,
106         py_base_dealloc,
107         0,
108         0,
109         0,
110         0,
111         py_base_repr,
112         0,0,0,0,0,0,0,0,0,
113         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
114         0,0,0,0,0,0,0,
115         Methods,
116         0,
117         0,
118         &SCA_IActuator::Type,
119         0,0,0,0,0,0,
120         py_base_new
121 };
122
123 PyMethodDef KX_NetworkMessageActuator::Methods[] = {
124         {NULL,NULL} // Sentinel
125 };
126
127 PyAttributeDef KX_NetworkMessageActuator::Attributes[] = {
128         KX_PYATTRIBUTE_STRING_RW("propName", 0, 100, false, KX_NetworkMessageActuator, m_toPropName),
129         KX_PYATTRIBUTE_STRING_RW("subject", 0, 100, false, KX_NetworkMessageActuator, m_subject),
130         KX_PYATTRIBUTE_BOOL_RW("usePropBody", KX_NetworkMessageActuator, m_bPropBody),
131         KX_PYATTRIBUTE_STRING_RW("body", 0, 16384, false, KX_NetworkMessageActuator, m_body),
132         { NULL }        //Sentinel
133 };
134
135 #endif // WITH_PYTHON