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