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