Merge of itasc branch. Project files, scons and cmake should be working. Makefile...
[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, KX_ACT_MESSAGE),
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         {NULL,NULL} // Sentinel
127 };
128
129 PyAttributeDef KX_NetworkMessageActuator::Attributes[] = {
130         KX_PYATTRIBUTE_STRING_RW("propName", 0, 100, false, KX_NetworkMessageActuator, m_toPropName),
131         KX_PYATTRIBUTE_STRING_RW("subject", 0, 100, false, KX_NetworkMessageActuator, m_subject),
132         KX_PYATTRIBUTE_BOOL_RW("usePropBody", KX_NetworkMessageActuator, m_bPropBody),
133         KX_PYATTRIBUTE_STRING_RW("body", 0, 16384, false, KX_NetworkMessageActuator, m_body),
134         { NULL }        //Sentinel
135 };