Blender  V2.59
SCA_ANDController.cpp
Go to the documentation of this file.
00001 /*
00002  * 'And' together all inputs
00003  *
00004  * $Id: SCA_ANDController.cpp 35169 2011-02-25 13:32:11Z jesterking $
00005  *
00006  * ***** BEGIN GPL LICENSE BLOCK *****
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License
00010  * as published by the Free Software Foundation; either version 2
00011  * of the License, or (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software Foundation,
00020  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00021  *
00022  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00023  * All rights reserved.
00024  *
00025  * The Original Code is: all of this file.
00026  *
00027  * Contributor(s): none yet.
00028  *
00029  * ***** END GPL LICENSE BLOCK *****
00030  */
00031 
00037 #include "SCA_ANDController.h"
00038 #include "SCA_ISensor.h"
00039 #include "SCA_LogicManager.h"
00040 #include "BoolValue.h"
00041 
00042 /* ------------------------------------------------------------------------- */
00043 /* Native functions                                                          */
00044 /* ------------------------------------------------------------------------- */
00045 
00046 SCA_ANDController::SCA_ANDController(SCA_IObject* gameobj)
00047         :
00048         SCA_IController(gameobj)
00049 {
00050 }
00051 
00052 
00053 
00054 SCA_ANDController::~SCA_ANDController()
00055 {
00056 }
00057 
00058 
00059 
00060 void SCA_ANDController::Trigger(SCA_LogicManager* logicmgr)
00061 {
00062 
00063         bool sensorresult = true;
00064 
00065         for (vector<SCA_ISensor*>::const_iterator is=m_linkedsensors.begin();
00066         !(is==m_linkedsensors.end());is++)
00067         {
00068                 SCA_ISensor* sensor = *is;
00069                 if (!sensor->GetState())
00070                 {
00071                         sensorresult = false;
00072                         break;
00073                 }
00074         }
00075         
00076         for (vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
00077         !(i==m_linkedactuators.end());i++)
00078         {
00079                 SCA_IActuator* actua = *i;
00080                 logicmgr->AddActiveActuator(actua,sensorresult);
00081         }
00082 }
00083 
00084 
00085 
00086 CValue* SCA_ANDController::GetReplica()
00087 {
00088         CValue* replica = new SCA_ANDController(*this);
00089         // this will copy properties and so on...
00090         replica->ProcessReplica();
00091 
00092         return replica;
00093 }
00094 
00095 #ifdef WITH_PYTHON
00096 
00097 /* ------------------------------------------------------------------------- */
00098 /* Python functions                                                          */
00099 /* ------------------------------------------------------------------------- */
00100 
00101 /* Integration hooks ------------------------------------------------------- */
00102 PyTypeObject SCA_ANDController::Type = {
00103         PyVarObject_HEAD_INIT(NULL, 0)
00104         "SCA_ANDController",
00105         sizeof(PyObjectPlus_Proxy),
00106         0,
00107         py_base_dealloc,
00108         0,
00109         0,
00110         0,
00111         0,
00112         py_base_repr,
00113         0,0,0,0,0,0,0,0,0,
00114         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
00115         0,0,0,0,0,0,0,
00116         Methods,
00117         0,
00118         0,
00119         &SCA_IController::Type,
00120         0,0,0,0,0,0,
00121         py_base_new
00122 };
00123 
00124 PyMethodDef SCA_ANDController::Methods[] = {
00125         {NULL,NULL} //Sentinel
00126 };
00127 
00128 PyAttributeDef SCA_ANDController::Attributes[] = {
00129         { NULL }        //Sentinel
00130 };
00131 #endif // WITH_PYTHON
00132 /* eof */