Merge of trunk into blender 2.5:
[blender.git] / source / gameengine / GameLogic / SCA_XORController.cpp
1 /**
2  * 'Xor' together all inputs
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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 #include "SCA_XORController.h"
33 #include "SCA_ISensor.h"
34 #include "SCA_LogicManager.h"
35 #include "BoolValue.h"
36
37 #ifdef HAVE_CONFIG_H
38 #include <config.h>
39 #endif
40
41 /* ------------------------------------------------------------------------- */
42 /* Native functions                                                          */
43 /* ------------------------------------------------------------------------- */
44
45 SCA_XORController::SCA_XORController(SCA_IObject* gameobj,
46                                                                          PyTypeObject* T)
47         :
48         SCA_IController(gameobj,T)
49 {
50 }
51
52
53
54 SCA_XORController::~SCA_XORController()
55 {
56 }
57
58
59
60 void SCA_XORController::Trigger(SCA_LogicManager* logicmgr)
61 {
62
63         bool sensorresult = false;
64
65         for (vector<SCA_ISensor*>::const_iterator is=m_linkedsensors.begin();
66         !(is==m_linkedsensors.end());is++)
67         {
68                 SCA_ISensor* sensor = *is;
69                 if (sensor->IsPositiveTrigger())
70                 {
71                         if (sensorresult == true)
72                         {
73                 sensorresult = false;
74                                 break;
75                         }
76             sensorresult = true;
77                 }
78         }
79         
80         CValue* newevent = new CBoolValue(sensorresult);
81
82         for (vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
83         !(i==m_linkedactuators.end());i++)
84         {
85                 SCA_IActuator* actua = *i;//m_linkedactuators.at(i);
86                 logicmgr->AddActiveActuator(actua,newevent);
87         }
88
89         // every actuator that needs the event, has a it's own reference to it now so
90         // release it (so to be clear: if there is no actuator, it's deleted right now)
91         newevent->Release();
92
93 }
94
95
96
97 CValue* SCA_XORController::GetReplica()
98 {
99         CValue* replica = new SCA_XORController(*this);
100         // this will copy properties and so on...
101         CValue::AddDataToReplica(replica);
102
103         return replica;
104 }
105
106
107
108 /* ------------------------------------------------------------------------- */
109 /* Python functions                                                          */
110 /* ------------------------------------------------------------------------- */
111
112 /* Integration hooks ------------------------------------------------------- */
113 PyTypeObject SCA_XORController::Type = {
114         PyObject_HEAD_INIT(&PyType_Type)
115         0,
116         "SCA_XORController",
117         sizeof(SCA_XORController),
118         0,
119         PyDestructor,
120         0,
121         __getattr,
122         __setattr,
123         0, //&MyPyCompare,
124         __repr,
125         0, //&cvalue_as_number,
126         0,
127         0,
128         0,
129         0
130 };
131
132 PyParentObject SCA_XORController::Parents[] = {
133         &SCA_XORController::Type,
134         &SCA_IController::Type,
135         &SCA_ILogicBrick::Type,
136         &CValue::Type,
137         NULL
138 };
139
140 PyMethodDef SCA_XORController::Methods[] = {
141         {NULL,NULL} //Sentinel
142 };
143
144 PyObject* SCA_XORController::_getattr(const STR_String& attr) {
145         _getattr_up(SCA_IController);
146 }
147
148 /* eof */