BGE: bookmark option on controller to make them run before all other controllers.
[blender.git] / source / gameengine / GameLogic / SCA_XNORController.cpp
1 /**
2  * 'Xnor' 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_XNORController.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_XNORController::SCA_XNORController(SCA_IObject* gameobj,
46                                                                          PyTypeObject* T)
47         :
48         SCA_IController(gameobj,T)
49 {
50 }
51
52
53
54 SCA_XNORController::~SCA_XNORController()
55 {
56 }
57
58
59
60 void SCA_XNORController::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->GetState())
70                 {
71                         if (sensorresult == false)
72                         {
73                                 sensorresult = true;
74                                 break;
75                         }
76                         sensorresult = false;
77                 }
78         }
79
80         for (vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
81         !(i==m_linkedactuators.end());i++)
82         {
83                 SCA_IActuator* actua = *i;
84                 logicmgr->AddActiveActuator(actua,sensorresult);
85         }
86 }
87
88
89
90 CValue* SCA_XNORController::GetReplica()
91 {
92         CValue* replica = new SCA_XNORController(*this);
93         // this will copy properties and so on...
94         replica->ProcessReplica();
95
96         return replica;
97 }
98
99
100
101 /* ------------------------------------------------------------------------- */
102 /* Python functions                                                          */
103 /* ------------------------------------------------------------------------- */
104
105 /* Integration hooks ------------------------------------------------------- */
106 PyTypeObject SCA_XNORController::Type = {
107 #if (PY_VERSION_HEX >= 0x02060000)
108         PyVarObject_HEAD_INIT(NULL, 0)
109 #else
110         /* python 2.5 and below */
111         PyObject_HEAD_INIT( NULL )  /* required py macro */
112         0,                          /* ob_size */
113 #endif
114         "SCA_XNORController",
115         sizeof(PyObjectPlus_Proxy),
116         0,
117         py_base_dealloc,
118         0,
119         0,
120         0,
121         0,
122         py_base_repr,
123         0,0,0,0,0,0,
124         py_base_getattro,
125         py_base_setattro,
126         0,0,0,0,0,0,0,0,0,
127         Methods
128 };
129
130 PyParentObject SCA_XNORController::Parents[] = {
131         &SCA_XNORController::Type,
132         &SCA_IController::Type,
133         &SCA_ILogicBrick::Type,
134         &CValue::Type,
135         NULL
136 };
137
138 PyMethodDef SCA_XNORController::Methods[] = {
139         {NULL,NULL} //Sentinel
140 };
141
142 PyAttributeDef SCA_XNORController::Attributes[] = {
143         { NULL }        //Sentinel
144 };
145
146 PyObject* SCA_XNORController::py_getattro(PyObject *attr) {
147         py_getattro_up(SCA_IController);
148 }
149
150 PyObject* SCA_XNORController::py_getattro_dict() {
151         py_getattro_dict_up(SCA_IController);
152 }
153
154 /* eof */