CEL

Public API Reference

tools/behaviourtree.h
00001 /*
00002     Crystal Space Entity Layer
00003     Copyright (C) 2004-2006 by Jorrit Tyberghein
00004   
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009   
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014   
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #ifndef __CEL_BEHAVIOUR_TREE__
00021 #define __CEL_BEHAVIOUR_TREE__
00022 
00023 #include "behaviourlayer/behave.h"
00024 #include "tools/decorators.h"
00025 #include "tools/parameters.h"
00026 #include "tools/rewards.h"
00027 #include "tools/triggers.h"
00028 
00029 //-------------------------------------------------------------------------
00030 // Behaviour tree nodes
00031 //-------------------------------------------------------------------------
00032 
00060 struct iBTNode : public virtual iBase
00061 {
00062   SCF_INTERFACE (iBTNode, 0, 0, 1);
00063 
00068   virtual bool Execute (const celParams& params) = 0;
00069 
00073   virtual bool AddChild (iBTNode* child) = 0;
00074 
00075 };
00076 
00077 //-------------------------------------------------------------------------
00078 // Specific behaviour tree node implementations.
00079 //-------------------------------------------------------------------------
00080 
00085 struct iBTAction: public virtual iBase
00086 {
00087   SCF_INTERFACE (iBTAction, 0, 0, 1);
00088 
00092   virtual void AddReward (iReward* reward) = 0;
00093 };
00094 
00099 struct iParameterCheckCondition: public virtual iBase
00100 {
00101   SCF_INTERFACE (iParameterCheckCondition, 0, 0, 1);
00102 
00106   virtual void SetParameter (const char* parameter) = 0;
00107 
00111   virtual void SetValue (const char* value) = 0;
00112 };
00113 
00114 
00120 struct iTriggerFiredCondition: public virtual iBase
00121 {
00122   SCF_INTERFACE (iTriggerFiredCondition, 0, 0, 1);
00123 
00127   virtual void SetTrigger (iTrigger* trigger) = 0;
00128 
00136   virtual void SetFireOnce (bool once) = 0;
00137 };
00138 
00139 //-------------------------------------------------------------------------
00140 
00144 #define CEL_DECLARE_BTNODE(name)                                        \
00145 class cel##name : public scfImplementation2<                            \
00146                 cel##name ,iBTNode, iComponent>                         \
00147 {                                                                       \
00148 private:                                                                \
00149   iObjectRegistry* object_reg;                                          \
00150   csRefArray<iBTNode> children;                                         \
00151 public:                                                                 \
00152   cel##name (iBase* parent);                                            \
00153   virtual ~cel##name () { }                                             \
00154   virtual bool Initialize (iObjectRegistry*);                           \
00155   virtual bool Execute (const celParams& params);                       \
00156   virtual bool AddChild (iBTNode* child);                               \
00157 };
00158 
00162 #define CEL_IMPLEMENT_BTNODE(name)                                      \
00163 cel##name::cel##name (iBase* parent)                                    \
00164  : scfImplementationType (this, parent), object_reg(0)                  \
00165 {                                                                       \
00166 }                                                                       \
00167 bool cel##name::Initialize (                                            \
00168         iObjectRegistry* object_reg)                                    \
00169 {                                                                       \
00170   cel##name::object_reg = object_reg;                                   \
00171   return true;                                                          \
00172 }                                                                       
00173 
00174 #endif // __CEL_BEHAVIOUR_TREE__

Generated for CEL: Crystal Entity Layer 2.0 by doxygen 1.7.6.1